I have a WCF service that handles errors by implementing an IErrorHandler and attaching it to the ChannelDispatcher's ErrorHandlers.
The IErrorHandler has a method called
bool HandleError(Exception error);
Which I implement and simply logs the exception to my DB.
My problem is that some exceptions occur before the web service's method gets called.
I also have a MessageInspector that I attach to the EndpointDispatcher that logs the soap messages.
Now, assuming I have an sql error and get an unhandled exception on my MessageInspector, the HandleError method gets called twice with the same sql connection error exception.
The problem is that it happens once when the connection's status is opened and once when the connection's status is closed.
Also, the second method on the IErrorHandler:
void ProvideFault(Exception error, MessageVersion version, ref Message fault);
doesn't get called, and then the framework wraps my exception with a FaultException, without letting me format it.
Is there any reason why the IErrorHandler behaves that way? Is there any other module I need to implement in order to handle unhandled exceptions that occur as part of the request's pipeline?
Why does the IErrorHandler get called when the connection is Closed?