Skip to main content
Exception Handling in WCF

Exception Handling in WCF | FaultException

Exception Handling in WCF

When an exception occurs in a WCF service, the service serializes the exception into a SOAP fault and then sends the SOAP fault to the client.

By default, unhandled exception details are not included int SOAP faults that are propagated to the client applications doe security reasons. Instead, a generic SOAP fault is returned to the client.

For debugging purpose, if you want to include exception details in SOAP faults then you need to enable includeExceptionDetialsInFaults attribute.

This can be done in two ways.

  1. Web.config/app.config
  2. Code

In config files you can set the attribute includeExceptionDetialsInFaults to True as shown below:

We can also achieve the above with the help of code as shown below:

WCF serializes exceptions to SOAP faults before reporting the exception information to the client. This is because exceptions are not allowed to be passed through a WCF service channel.

SOAP faults are in XML format and are platform independent. A typical SOAP fault contains:

  1. FaultCode
  2. FaultReason
  3. Detail elements

The Detail element can be used to include any custom XML.

Note: BasicHttpBinding uses SOAP 1.1 whereas, other built-in WCF bindings use SOAP 1.2.

For more details you can refer – MSDN


DotNetCrunch is a popular blog for latest Microsoft® technologies which is aimed for beginners and intermediate level professionals.