title: .Net code to catch an HTTP 500 error response from an .asmx web service
body: <p>Is there a way to catch the HTTP 500 error returned by an .asmx web service from a .Net client?</p>
  
  <p>Using .Net 4.5 (VS2015), the .Net client code consumes the .asmx web service and calls it using the code below:</p>
  
  <pre><code>var client = new WebserviceApi.MyServiceSoapClient();
  
  var response = client.MyWebServiceMethod();
  </code></pre>
  
  <p>If the .asmx web service returns an HTTP 500 error with a SOAP message containing the error message details, the "response" variable is set to null. </p>
  
  <p>Using Fiddler, the traffic shows the HTTP 500 response from the .asmx web service. The response contains a SOAP XML message with details on the error.</p>
  
  <p>No exception is thrown or caught in the .Net client code, execution continues as normal.</p>
  
  <p>This means there is no information for the client to pick up regarding the nature of the exception. All the client code can do is check if "response" is null, but the exception message is not available to the client code.</p>
  
  <p>Is there any way to force the .Net client code to throw an exception if the .asmx web service returns an HTTP 500 response so that the error message can be checked/logged?</p>