Freigeben über


Scenario 2 - SOAP based API returning 404 and 500 HTTP status codes

Referring to my blog on Azure API Management Troubleshooting Series, this is the second scenario of the lab. Please make sure you have followed the lab setup instructions as per this, to recreate the problem.

 

Symptom

The Calculator API can perform four operations - Add, Subtract, Multiply and Divide based upon two input parameters intA and intB. Name of the operations are self-explanatory to what function they perform. It’s an ASMX service (https://www.dneonline.com/calculator.asmx) following SOAP 1.1 protocol so the input parameters are passed in the soap envelope body section. Add and Subtract operations are working fine as expected, but we are encountering HTTP 404 while invoking Multiply operation and HTTP 500 while invoking Divide operation.
Expected Output of Multiply operation should be something like below:

 <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <MultiplyResponse xmlns="https://tempuri.org/">
         <MultiplyResult>int</MultiplyResult>
      </MultiplyResponse>
   </soap:Body>
</soap:Envelope>

 

Expected Output of Divide operation should be something like below:

 <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <DivideResponse xmlns="https://tempuri.org/">
         <DivideResult>int</DivideResult>
      </DivideResponse>
   </soap:Body>
</soap:Envelope>


Troubleshooting

We need to understand who is throwing these HTTP 404 and 500 responses. Is it APIM or the backend SOAP API ? Again the best way to get that answer is to collect APIM inspector trace to inspect request and response.

  • Multiply operation throwing HTTP - 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
  • If you examine the backend section of APIM inspector trace, the same observation is quite evident from the message as well:

{
"backend": [
{
"source": "configuration",
"timestamp": "2018-07-29T12:30:08.3500317Z",
"elapsed": "00:00:00.7276962",
"data": {
"message": "Unable to identify Api or Operation for this request. Responding to the caller with 404 Resource Not Found."
}
}
]
}

 

  • Hence you should first examine the request url and headers sent from APIM to the backend API from the Test tab and compare it with the sample of SOAP request for Multiply operation - https://www.dneonline.com/calculator.asmx.

Request headers from APIM inspector trace looks something like below:

{
"data": {
"request": {
"method": "POST",
"url": "https://pratyay.azure-api.net/calc",
"headers": [
{
"name": "Ocp-Apim-Subscription-Key",
"value": "34ae22db7f2c4c5da7b74a55adf03223"
},
{
"name": "X-Forwarded-For",
"value": "223.226.79.35"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Content-Length",
"value": "292"
},
{
"name": "Content-Type",
"value": "application/soap+xml; action=https://tempuri.org/Multiply"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.5"
},
{
"name": "Host",
"value": "pratyay.azure-api.net"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/apimanagement/Content/1.0.385.3/apimap/apimap-apis/index.html?locale=en&trustedAuthority=https://ms.portal.azure.com"
}
]
}
}
}

 

  • As per the backend ASMX service definition you would notice SOAP 1.1 request needs a request header SOAPAction which is missing in the request sent from APIM.
  Host: www.dneonline.com
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 SOAPAction: "https://tempuri.org/Multiply" 

 

  • Adding SOAPAction header with the value https://tempuri.org/Multiply will resolve the problem. You can add the request header under the Frontend definition of the Multiply operation and set the value as a default one under Headers tab so that you don’t have to send that header every time on each request.

 

add_request_header

 

  • Divide operation throwing HTTP 500 (Internal Server Error) status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
  • In other words, backend service is not able to process your request body sent from APIM. Let's examine the request body sent from APIM.
  • Upon checking the SOAP body you would notice that denominator (intB) is set as zero, leading to an unhandled exception, hence causing HTTP 500 (Internal Server Error).
 POST calc HTTP/1.1

Host: pratyay.azure-api.net
SOAPAction: https://tempuri.org/Divide
Cache-Control: no-cache
Ocp-Apim-Trace: true
Content-Type: application/soap+xml; action=https://tempuri.org/Divide
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="https://www.w3.org/2003/05/soap-envelope">
  <Body>
    <Divide xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns="https://tempuri.org/">
      <intA>1</intA>
       <intB>0</intB> 
    </Divide>
  </Body>
</Envelope>
  • If you check the request content representation from the Request tab present in Frontend definition of the Divide operation, you would notice that intB value is set to zero. You need to change the value of intB to a non-zero value and it should resolve the issue.

 

change_request_body

 

Hope you have learnt how to troubleshoot request failures in APIM.

Happy Learning !