SOAP to JSON Conversion resulting Internal server error

Vijay Akula 66 Reputation points
2023-06-22T14:58:43.73+00:00

Hi,

I am trying to convert soap to JSON in the outbound policy, it's basically the policy generated while importing the WSDL for some reason it just does not work. I also tried body.Envelope.Body.someResponse.someName but no use, I can confirm that backend is responding HTTP 200 and the SOAP response is as expected. Please suggest the best course of action. Here is my outbound policy.

<outbound>
	<base />
    <choose>
       	<when condition="@(context.Response.StatusCode < 400)">
           	<set-body template="liquid">
               	{
					"Name": {{body.envelope.body.someResponse.someName | Replace: '\r', '\r' | Replace: '\n', '\n' | Replace: '([^\\](\\\\)*)"', '$1\"'}} }}
                 }
			</set-body>
		</when>
		<otherwise>
			<set-variable name="old-body" value="@(context.Response.Body.As<string>(preserveContent: true))" />
                <set-body template="liquid">{
            		"error": {
                	"code": "{{body.envelope.body.fault.faultcode}}",
                	"message": "{{body.envelope.body.fault.faultstring}}"
            		}
        		}</set-body>
		</otherwise>
	</choose>
</outbound>

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,447 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2023-06-26T15:07:05.56+00:00

    Vijay Akula Thanks for sharing the additional details. I have tested the sample policy snippet you shared with echo endpoint [http://echoapi.cloudapp.net/api/resource] and didn't produce any issue. Here are the details:

    Output:User's image

    Code snippet:

    <outbound>
            <set-variable name="response-body" value="@(context.Response.Body.As<string>(preserveContent: true))" />
            <set-body template="liquid">{
                		"error": {
                    	"code": "{{body.envelope.body.someResponse.SomeName}}"
                		}
            		}</set-body>
            <base />
        </outbound>
    

    Request info:

    User's image

    I understand you may not be able to share the full sample request, response or exact policy info. Make sure to validate the casing such as fault, faultcode in the actual response.

    If you still need help, we can connect offline and send an email to azcommunity@microsoft.com referencing this thread with your subscription ID, details and subject as "Attn: Muthu". I will assist you with next steps.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.