Reputation: 5719
I am using Azure API Management REST API's to import a WSDL and convert it to a REST endpoint calling SOAP backend.
However when you import the WSDL all the methods are imported as POST (which makes sense since you need to send the soap envelope). Now I want to convert the operation from POST to GET via the REST API (which I can do through portal).
Has anyone tried that before, and if yes which API's should I call?
Upvotes: 3
Views: 768
Reputation: 3967
For this case I used a public soap service: https://www.dataaccess.com/webservicesserver/numberconversion.wso?op=NumberToDollars
I imported this SOAP service to API Management:
Request-Body:
<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
<Body>
<NumberToDollars xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.dataaccess.com/webservicesserver/">
<dNum>1</dNum>
</NumberToDollars>
</Body>
</Envelope>
The NumberToDollars operation has to read the XML, transform it into JSON, and pass the data to a GET API.
For testing purposes I created an mocked Operation which returns 200: https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/200/test
<policies>
<inbound>
<base />
<set-variable name="num" value="@{
string xml = context.Request.Body.As<string>(preserveContent: true);
xml = Regex.Unescape(xml);
// Remove the double quotes
xml = xml.Remove(0,1);
xml = xml.Remove(xml.Length-1,1);
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
var data = JObject.Parse(JsonConvert.SerializeObject(doc));
JObject envelope = data["Envelope"] as JObject;
JObject body = envelope["Body"] as JObject;
JObject numberToDollars = body["NumberToDollars"] as JObject;
return numberToDollars["dNum"].Value<string>();
}" />
<set-method>GET</set-method>
<set-backend-service base-url="https://rfqapiservicey27itmeb4cf7q.azure-api.net/echo/200/" />
<rewrite-uri template="@("/test?q=" + context.Variables.GetValueOrDefault<string>("num"))" copy-unmatched-params="false" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
The JSON document generated from XML:
{
"?xml": {
"@version": "1.0",
"@encoding": "utf-8"
},
"Envelope": {
"@xmlns": "http://www.w3.org/2003/05/soap-envelope",
"Body": {
"NumberToDollars": {
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xmlns": "http://www.dataaccess.com/webservicesserver/",
"dNum": "1"
}
}
}
}
Upvotes: 1