WCF Exception Handling

WCF introduces new exception handling concepts to address the differences between traditional component-oriented systems and SOA. While traditional component-oriented systems can share native types for exception reporting and handling, this does not work across service boundaries. Exceptions are serialized as SOAP faults between clients and services. The service model can handle this automatically by converting exceptions into faults, or faults can be explicitly created using new CLR types introduced with WCF for this purpose.

In this section, I’ll introduce the concept of fault exceptions and then provide a high-level explanation of the way services and clients deal with exceptions and faults.

Fault Exceptions

WCF introduces several new exception types, most of which derive from a common base type, CommunicationException. Among the types that inherit CommunicationException, FaultException is the most important. Both types are from the System.ServiceModel namespace.

Not surprisingly, FaultException properties are closely related to the SOAP fault— they are Action, Code, and Reason. In addition, FaultException provides access to the entire message associated with the SOAP fault through its Message property. It is through this property that the detail element of the fault can be retrieved, for example.

There is also a generic version of the FaultException: FaultException<T>. This type provides strongly typed access to the detail element of the fault through its ...

Get Learning WCF now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.