O'Reilly logo

Programming WCF Services, 2nd Edition by Juval Lowy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error-Handling Extensions

WCF enables developers to customize the default exception reporting and propagation behavior, and even to provide for a hook for custom logging. This extensibility is applied per channel dispatcher (that is, per endpoint), although you are most likely to simply utilize it across all dispatchers.

To install your own error-handling extension, you need to provide the dispatchers with an implementation of the IErrorHandler interface, defined as:

public interface IErrorHandler
{
   bool HandleError(Exception error);
   void ProvideFault(Exception error,MessageVersion version,ref Message fault);
}

Any party can provide this implementation, but typically it will be provided either by the service itself or by the host. In fact, you can have multiple error-handling extensions chained together. You will see how to install the extensions later in this section.

Providing a Fault

The ProvideFault( ) method of the extension object is called immediately after any unhandled exception is thrown by the service or any object on the call chain downstream from a service operation. WCF calls ProvideFault( ) before returning control to the client, and before terminating the session (if present) and disposing of the service instance (if required). Because ProvideFault( ) is called on the incoming call thread while the client is still blocked waiting for the operation to complete, you should avoid lengthy execution inside ProvideFault( ).

Using ProvideFault( )

ProvideFault( ) is called regardless ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required