WCF FaultHandling

01. December 2013 WCF 0

The WCF service cannot return a .NET exception to the client. The WCF service and the client communicate by passing SOAP messages. If an exception occurs, the WCF runtime serializes the exception into XML and passes that to the client.

By default, the service does not send any information explaining what happened. WCF does not reveal details about what the service does internally. This makes the service more secure.

WCF services provide a very nice abstraction over these in form of FaultException and the services can easily propagate the exception information to the client using the FaultException and FaultContract.

Throw a FaultException in the Service Implementation

WCF services also provides a way for us to throw custom objects in our fault exceptions. These custom objects will contain the detailed information about the exception. These objects will have to be exposed as the FaultContract from the service.

Throw this type of exception in the service implementation:

And catch it in the application code:

Further Reading

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.