views:

60

answers:

3

If an exception occurs in my WCF service, what is the best way to communicate that error to the client?

Should I log it on the service and rethrow a soap exception? Or should I log it and return a user friendly message?

+1  A: 

I would log it and return a FaultException. When you create the FaultException you can pass a user friendly message within it back to the client.

Steve Ellinger
A: 

An exception is supposed to be an exceptional event, so you shouldn't worry about nice messages. If exceptions only occur when you have a bug, just rethrow it as a generic exception and log it. Should not be a problem.

However, when the exceptions occur as part of your normal process, returning nice messages would be a good idea.

Pieter
+2  A: 

Using strongly typed or non-typed FaultException is a way to accomplish this. There is an excellent article Simplifying WCF: Using Exceptions as Faults that describes how to use each. As the article points out, depending on complexity of your service you may opt to choose simpler untyped FaultException and pass exception info to the client.

zam6ak