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 acces开发者_C百科s 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?
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();
...
}
}
精彩评论