IErrorHandler
Realistically, it is impossible for the service designer to have full knowledge of all the exceptions that may be thrown by downstream business components as the operation executes. I’ve already established that you shouldn’t indiscriminately throw unhandled exceptions as faults. You also don’t necessarily want to wrap all uncaught exceptions as faults. You may, however, want to log all uncaught exceptions and, if appropriate, convert some of those exceptions to faults to prevent the channel from faulting.
Adding common error handling code such as this directly to each service operation would
be cumbersome and unmanageable. For this reason, WCF provides support for error handler
components. Error handlers are types that implement IErrorHandler and are associated with the service behavior. In this section,
you will learn how to create and configure a custom error handler. In the process, you’ll
learn how to dynamically configure the ServiceHost using
an IServiceBehavior extension, using a custom attribute,
and by extending ServiceHost. You’ll do a lab that
exercises the basic concepts first.
Lab: Intercepting Uncaught Exceptions with IErrorHandler
The solution for this lab is much the same as the other two in this chapter. Through the client interface, you can upload photos to a service, and the service is currently configured with a bad directory name for file uploads. In this lab, you will explore how to create a custom error handler to process uncaught exceptions and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access