Tappy
Tappy

Reputation: 105

How to pass DateTime for a SOAP request to a azure web api?

I am creating a web api on Azure (APIM). This web api access a method on from an on prem service. The request object passed should be SOAP. This request object also contains a Date time field. I am trying from quite sometime now but my request is failing with the following error: There was an error deserializing the object of type Core.Service.DataContracts.ExternalData. The value '' cannot be parsed as the type 'DateTime'.

I am passing the following Request Object, through Postman to test my web api: { "integrationpartnername" : "Hi-Marley", "actioncategory" : "TextChat", "actioncode" : "OpenClaim", "actiondescription" : "Text Chat Open Claim", "transmissionmethod" : "WebService", "requeststatus" : "Complete", "requestdate" : "2019-08-02T10:22:49", "requestmessage" : "Hi Marley first third party log from apim.", "responsedate" : "2019-08-02T10:22:49" }

Any pointers are much appreciated. Edit: Adding the screenshot of the Postman:

enter image description here

Upvotes: 0

Views: 2573

Answers (2)

Tappy
Tappy

Reputation: 105

Running the test in the portal I could see in the trace that the date was being converted from 2019-08-02T10:22:49.463Z in the JSON body to 8/12/2019 10:22:49 AM in the SOAP body. The WCF service was throwing a deserialization exception because that datetime format cannot be parsed. The solution is to format the date in the liquid syntax, like this

{{body.RequestDate | Date: "yyyy-MM-ddTHH:mm:ss"}}. The correct date format to use was not as straight forward to find since the liquid documentation says to use Ruby strftime format, but that did not work for me https://shopify.github.io/liquid/filters/date/. Apparently the APIM uses dotLiquid and not basic liquidSee https://azure.microsoft.com/en-us/blog/deep-dive-on-set-body-policy/ for reference.

Upvotes: 0

Hury Shen
Hury Shen

Reputation: 15734

This issue may caused by the date/time string is not the expected format, you can have a try with this format: "2019-08-12T12:00:00.000Z" and change the format code in your api. For further information, you may refer to the pages below:

http://www.mirthproject.org/community/forums/showthread.php?t=9407 http://tech.forums.softwareag.com/techjforum/posts/list/31905.page

Upvotes: 1

Related Questions