How to handle unhandled exceptions in downstream services

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

Implement a global exception handler to handle unhandled exceptions in downstream services. Implement a global exception handler by subscribing to the Faulted event of a service host object.
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…
}

Last edited May 8, 2008 at 3:37 AM by prashantbansode, version 1

Comments

No comments yet.