This project is read-only.

How to Handle Unhandled Exceptions In Downstream Services

- J.D. Meier, Carlos Farre, Jason Taylor, Prashant Bansode, Steve Gregersen, Madhu Sundararajan, Rob Boucher

Use a global exception handler to catch unhandled exceptions and prevent them from being propagated to the client.

You can handle the unhandled exceptions in a WCF service by subscribing to the Faulted event of a service host object. By subscribing to this event you can determine the cause of a failure, and then perform the necessary actions to abort or restart the service.

The following code snippet shows how to subscribe to the Faulted event:
// hosting a WCF service 
ServiceHost customerServiceHost;
customerServiceHost = new ServiceHost(…);
// Subscribe to the Faulted event of the customerServiceHost object
customerServiceHost.Faulted += new EventHandler(faultHandler);
// FaultHandler method - invoked when customerServiceHost enters the Faulted state
void faultHandler(object sender, EventArgs e)
{     // log the reasons for the fault…

Additional Resources

Last edited Jun 13, 2008 at 7:42 PM by prashantbansode, version 1


No comments yet.