We are moving from old SOAP Web Service calls for our customers to call to new Azure Functions/REST API calls.
We would like to be able to use Azure API Management to convert the OLD SOAP messages into REST calls for our customers so that they do not have to rewrite their side and can continue to use the SOAP messages.
I've found little to no documentation on how to make this work. I've tried fiddling with it using the WSDL from our Old SOAP services and then pointing that to the Azure API but I get nothing but errors.
I don't see a way to get any detailed info.
I understand that I need to use the Liquid Templates to transform the SOAP Message which has about 10 properties and is an array of data into JSON but I've had zero luck figuring that out.
Does anyone have any resources on how to get this to work?
Adding the below example data.
This is what we call the Legacy SOAP Message.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ad="http://ad-c.com/">
<soapenv:Header/>
<soapenv:Body>
<ad:ImportItemMovement>
<ad:authenticationToken>0badec32-81f7-4f88-813f-2dbfb62b4484</ad:authenticationToken>
<ad:movementArray>
<ad:WSItemMovementInfo>
<ad:OrgUnitNum>52</ad:OrgUnitNum>
<ad:MovementDateTime>2020-10-06T09:55:50</ad:MovementDateTime>
<ad:RetailSold>5.99</ad:RetailSold>
<ad:QtySold>300</ad:QtySold>
<ad:ItemNum>123456789</ad:ItemNum>
<ad:UpcNum>00021234500000</ad:UpcNum>
</ad:WSItemMovementInfo>
<ad:WSItemMovementInfo>
<ad:OrgUnitNum>54</ad:OrgUnitNum>
<ad:MovementDateTime>2020-10-06T09:55:50</ad:MovementDateTime>
<ad:RetailSold>5.99</ad:RetailSold>
<ad:QtySold>300</ad:QtySold>
<ad:ItemNum>123456789</ad:ItemNum>
<ad:UpcNum>00021234500000</ad:UpcNum>
</ad:WSItemMovementInfo>
</ad:movementArray>
</ad:ImportItemMovement>
</soapenv:Body>
</soapenv:Envelope>
Here is the CURRENT policy with the help of @DSpirit
<policies>
<inbound>
<base />
<find-and-replace from="ad:" to="" />
<find-and-replace from="soapenv:" to="" />
<xml-to-json kind="direct" apply="always" consider-accept-header="true" />
<trace source="inbound">@(context.Request.Body.As<string>(true))</trace>
<set-body>@{
var body = JObject.Parse(context.Request.Body.As<string>());
return body["Envelope"]["Body"]["ImportItemMovement"]["movementArray"]["WSItemMovementInfo"]?.ToString();
}</set-body>
<set-body template="liquid">
[
{% JSONArrayFor item in body %}
{
"StoreNumber": {{ item.OrgUnitNum }},
"BarcodeNumber": "{{ item.UpcNum }}",
{% if item.WgtSold %}
"Type": "W",
"QuantitySold": {{ item.WgtSold }},
{% endif %}
{% if item.QtySold %}
"Type": "Q",
"QuantitySold": {{ item.QtySold }},
{% endif %}
"TotalRetail": {{ item.RetailSold }},
{% if item.onPromotion %}
"PromotionType": {{ item.onPromotion }},
{% else %}
"PromotionType": 0,
{% endif %}
"SerialNumber": "{{ item.labelSerialNum }}",
"MovementDateTime": "{{ item.MovementDateTime }}"
}
{% endJSONArrayFor %}
]
</set-body>
<!-- Here you should forward the request to the function backend instead of returning it -->
<set-backend-service base-url="https://proxy.freshiq.com/prod/inventory/" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Here is what the Azure REST API is expecting.
[{
"StoreNumber": 0,
"BarcodeNumber": "string",
"Type": "string",
"QuantitySold": 0.5229864343061676,
"TotalRetail": 0.2568850594082819,
"PromotionType": 0,
"SerialNumber": "string",
"MovementDateTime": "string"
},
{
"StoreNumber": 0,
"BarcodeNumber": "string",
"Type": "string",
"QuantitySold": 0.5229864343061676,
"TotalRetail": 0.2568850594082819,
"PromotionType": 0,
"SerialNumber": "string",
"MovementDateTime": "string"
}]
The mapping from SOAP XML to REST JSON is:
OrgUnitNum = StoreNumber
UpcNum = BarcodeNumber
If WgtSold exits Then Type = "W"
If QtySold exist then Type = "Q"
WgtSold if exists or QtySold if exists = QuantitySold
RetailSold = TotalRetail
onPromotion = PromotionType
labelSerialNum = SerialNumber
MovementDateTime = MovementDateTime
With the above it does seem to work with 1 exception the JSON that is produced the first record of the 2 has the names of the SOAP fields not the JSON ones but the second record in the "FOR" loop is correct. I'm not sure what would cause that.