Recently working with a partner I came across a solution for a limitation in WCF error handling. The root of the issue is a difference between SOAP 1.1 and SOAP 1.2 in the allowed HTTP status codes when a SOAP fault is returned. For SOAP 1.1, the status code must be 500 “Internal Server Error”. For SOAP 1.2, it varies based on the type of the SOAP fault. For env:Sender, the status code is 400 “Bad Request”, but for anything else it is 500 like SOAP 1.1.
When WCF receives an HTTP error code it wraps it in an exception, FaultException in the case of 500 and ProtocolException in the case of 400. This means when a service returns a SOAP fault with a 400 status code, all the information about it is lost instead of showing up in a nicely populated FaultException. Actually it isn’t lost, it’s just hidden. The InnerException of the ProtocolException is a WebException generated by the HTTP response. And on the WebException, lo and behold, is the the actual WebResponse with that SOAP fault just waiting to be read out of the stream. So with a little manipulation you can turn these ProtocolExceptions into FaultExceptions:
Note if there isn’t a SOAP fault in the response, this will throw again, you’ll want to handle that in the best way for your application.