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 ...
Get Programming WCF Services, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.