Is there a way to catch the HTTP 500 error returned by an .asmx web service from a .Net client?
Using .Net 4.5 (VS2015), the .Net client code consumes the .asmx web service and calls it using the code below:
var client = new WebserviceApi.MyServiceSoapClient();
var response = client.MyWebServiceMethod();
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.
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.
No exception is thrown or caught in the .Net client code, execution continues as normal.
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.
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?