I'm accessing a SOAP 1.1 web service, and it's returning a fault. The web service does not define any fault contract in the WSDL as far as I can see. My WCF client maps the fault to a FaultException (rather than a FaultException<T>). This all makes sense. The problem is that the service is returning some useful diagnostic information in the detail element of the fault, which I'd like to access so that I can dump it to a trace log. It seems that FaultException does not provide any access to the detail element, presumably because without a fault contract it doesn't know what is in there.
But I don't need to deserialize the detail XML - just the raw XML as a string will do fine for diagnostic purposes.
Is there any way to get access to the detail XML from a WCF client, in this scenario?
WCF provides the option to handle and convey the error message to the client from a service using a SOAP Fault Contract. To support SOAP Faults, WCF provides the FaultException class. This class has two forms: FaultException: to send an untyped fault back to the caller.
In a service, use the FaultException class to create an untyped fault to return to the client for debugging purposes. In a client, catch FaultException objects to handle unknown or generic faults, such as those returned by a service with the IncludeExceptionDetailInFaults property set to true .
SOAP stands for simple object access protocol. In WCF the main thing is that the communication between the server and client. The communication takes place by messages with some transport layer. The main need of calling a service is to do the data transfer between the server and client.
As detailed here: http://www.theruntime.com/blogs/jacob/archive/2008/01/28/getting-at-the-details.aspx
you can use this workaround to obtain the details:
} catch (FaultException soapEx)
{
MessageFault mf = soapEx.CreateMessageFault();
if (mf.HasDetail)
{
XmlDictionaryReader reader = mf.GetReaderAtDetailContents();
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With