WCF: Server-side error handling. best practice

I am writing a WCF service and want to keep an activity log: trace, warnings and error messages. A very simple approach is to wrap all the service code inside the try/catch sections and write error messages from the catch part, reconstructing exceptions to service errors of the service.

I suppose it would be nice if there was one code point to catch all the uncaught exceptions instead of dozens of try/catch sections. It would also be useful to write the parameters of the contract method from this point to provide detailed error information.

Is this possible with WCF?

What is the best practice for organizing error handling within WCF services?

Thank you in advance!

+6
wcf
source share
3 answers

See IErrorHandler interface

It allows the contractor to manage the error message returned to the caller and, optionally, to perform custom error handling, such as logging

You can implement your service behavior (see the IServiceBehavior interface) and add a handler to the ChannelDispatcher error handlers.

See Handling WCF Exceptions with IErrorHandler for details .

+4
source share
+2
source share

I'm not sure if this works in WCF, but you can try the AppDomain.UnhandledException event.

0
source share

All Articles