Unable to parse soap response using Azure API Management liquid template

Suraj Yedre 1 Reputation point
2020-10-01T13:08:22.673+00:00

There is not much documentation and examples for SOAP-pass through

I want to change the output format of the soap response, before passing it onto the client. I am using the soap pass-through as specified in the documentation https://azure.microsoft.com/en-ca/blog/soap-pass-through/

Soap service used in this example is hosted at https://fazioapisoap.azurewebsites.net/FazioService.svc?singleWsdl

I am unable to extract the soap response in the liquid template. Soap response does get generated, however, there is no data.

e.g:

if i have below response

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetOpenOrdersResponse xmlns="http://tempuri.org/">
<GetOpenOrdersResult xmlns:a="http://schemas.datacontract.org/2004/07/FazioAPISoap" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:order_id>10001</a:order_id>
</a:OrderSummary>
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:order_id>10010</a:order_id>
</a:OrderSummary>
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:order_id>10019</a:order_id>
</a:OrderSummary>
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:order_id>10045</a:order_id>
</a:OrderSummary>
</GetOpenOrdersResult>
</GetOpenOrdersResponse>
</s:Body>
</s:Envelope>

what i want is
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetOpenOrdersResponse xmlns="http://tempuri.org/">
<GetOpenOrdersResult xmlns:a="http://schemas.datacontract.org/2004/07/FazioAPISoap" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:Neworder_id>10001</a:Neworder_id>
</a:OrderSummary>
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:Neworder_id>10010</a:Neworder_id>
</a:OrderSummary>
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:Neworder_id>10019</a:Neworder_id>
</a:OrderSummary>
<a:OrderSummary>
<a:order_header_data>
<a:Bar>false</a:Bar>
<a:Foo>Things</a:Foo>
</a:order_header_data>
<a:Neworder_id>10045</a:Neworder_id>
</a:OrderSummary>
</GetOpenOrdersResult>
</GetOpenOrdersResponse>
</s:Body>
</s:Envelope>

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,959 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mike Urnun 9,786 Reputation points Microsoft Employee
    2020-11-19T23:16:21.127+00:00

    Hello @Suraj Yedre

    My apologies for the late reply. In case this is still an issue for you or anyone else revisiting this post, here's how I made it work. For this type of transformation, APIM offers the <xsl-transform> policy which is documented here: Transform XML using an XSLT

    Since you wanted to transform the <a:order_id> node into <a:neworder_id> node in the output of the response, you can add the following XSLT into the <outbound> section of your policy snippets:

    <xsl-transform>  
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://schemas.datacontract.org/2004/07/FazioAPISoap">  
            <xsl:output omit-xml-declaration="yes" method="xml" indent="yes" />  
            <xsl:template match="//a:order_id">  
                <a:neworder_id>  
                    <xsl:apply-templates select="@*|node()" />  
                </a:neworder_id>  
            </xsl:template>  
            <!-- Template to match all nodes, copy them and then apply templates to children. -->  
            <xsl:template match="@*|node()">  
                <xsl:copy>  
                    <xsl:apply-templates select="@*|node()" />  
                </xsl:copy>  
            </xsl:template>  
        </xsl:stylesheet>  
    </xsl-transform>  
    

    When I test the above, I'm able to get the following payload where the intended transformation has successfully occurred:

    41232-image.png

    I hope this is helpful, please let me know if any questions on this matter, and I'd be happy to assist.

    0 comments No comments