Smartservice REST body issue

Home Forums kbmMW Smartservice REST body issue

This topic contains 2 replies, has 2 voices, and was last updated by  kimbomadsen 7 months, 2 weeks ago.

  • Author
    Posts
  • #53396

    mrluigi2017
    Participant

    Hi,

    First of all happy 2019!

    For one reason or another the body parameter in the following method is not marshalled into the  TSomeTest object.

    [kbmMW_Method]
    [kbmMW_Rest(‘method:post, path:”some-test”‘)]
    function AddSomeTest([kbmMW_Rest(‘value:”body”‘)] const ATest: TSomeTest): string;

    The TSomeTest looks like this:

    [kbmMW_Root(‘some_test’, [mwrfIncludeOnlyTagged])]
    TSomeTest = class
    private
    FMyName: string;
    FMyAge: integer;
    public
    [kbmMW_Attribute(‘my_name’)]
    property MyName: string read FMyName write FMyName;
    [kbmMW_Attribute(‘my_age’)]
    property MyAge: integer read FMyAge write FMyAge;
    end;

    I have added the following code in the initialization section

    TkbmMWRTTI.EnableRTTI([TSalesInvoice, TSalesInvoiceRead, TSomeTest]);
    kbmMWRegisterKnownClasses([TSalesInvoice, TSalesInvoiceRead, TSomeTest]);

    When I make a http post request with Fiddler I get an invalid type cast exception.

    I found out that I do have access to the body parameter, so I think that some goes wrong with marshalling. If I just marshal/unmarshal with TkbmMWJSONMarshal(m).ValueFromString etc. it does work fine.

    Any suggestion what might be the cause of this exception?

    I am using kbmmw 5.0.6.20

    Thanks in advance.

     

    p.s. the subject line input has a white font on a white background here in Firefox and Chrome

     

  • #53399

    mrluigi2017
    Participant

    I looks like the mime type var never makes it to the UmarshalBody method in kbmMWSmartServiceUtils.

    My http header looks like this:

    User-Agent: Fiddler
    Mime-Type: application/json
    Host: 192.168.0.56
    Content-Length: 39

    Am I doing something wrong or is this a bug?

    • #53401

      kimbomadsen
      Keymaster

      Hi,

      You will definitely want to use latest versions for these features, as they continue to improve.

      It should work in 5.07, and it is definitely working in the 5.07.10 update that I will be releasing shortly.

      // This method gets a person in the body and echoes it back again.
      // Since we want the provided value echoed right back we dont want
      // the framework to free the argument automatically.
      // The result is freed when needed.
      [kbmMW_Method(‘EchoPerson’)]
      [kbmMW_Rest(‘method:post, path: “echoPerson”‘)]
      function EchoPerson([kbmMW_Rest(‘value: “body”, free:false’)] const APerson:TPerson):TPerson;

You must be logged in to reply to this topic.