Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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 (http://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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   soap:Body>
      MultiplyResponse xmlns="http://tempuri.org/">
         MultiplyResult>intMultiplyResult>
      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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   soap:Body>
      DivideResponse xmlns="http://tempuri.org/">
         DivideResult>intDivideResult>
      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 - http://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=http://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: "http://tempuri.org/Multiply"
  • Adding SOAPAction header with the value http://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.

  • 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: http://tempuri.org/Divide
Cache-Control: no-cache
Ocp-Apim-Trace: true
Content-Type: application/soap+xml; action=http://tempuri.org/Divide
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••

1      0
    
  • 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.

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

Happy Learning !

Share the post

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

×

Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription

×