I have developed a small WCF service which handles HTTP request.
I want to be aware of every fault that happens:
- everything that causes 500 Internal Server Error from the contracts view
- everything that causes a CommunicationException from the bindings view (I’ve written a custom one but am using standard ones also)
The errors should be put into the windows event log.
My question is:
- Is there some possibility to add a central event handler for the whole WCF stack which captures all Exceptions and prints them into the event log?
Greetings.
On the server side – yes, as John already pointed out, you can basically implement the
IErrorHandlerinterface on your service class and capture all errors on that side.However, on the client side, you’ll just have to use good old .NET
try {...} catch {...}to secure all service calls – after all, you could potentiallyThose would be
CommunicationExceptions(or descendants thereof) and must be handled on the client side as they happen.So you can handle the server side of things centrally (at least as long as the message has gotten through to your service class and is being processed) – anything else must be handled separately.
Marc