Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access SOAP 1.1 fault detail from WCF client (no fault contract)

Tags:

soap

wcf

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?

like image 919
Andy Avatar asked Jan 25 '10 18:01

Andy


People also ask

How fault contract is implemented in WCF?

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.

How do you handle a fault exception in C#?

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 .

What is SOAP in WCF service?

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.


1 Answers

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();    
        ...    
    }    
}
like image 101
GaussZ Avatar answered Sep 25 '22 14:09

GaussZ