Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use WCF Fault Exception

Tags:

c#

.net

wcf

fault

I have a simple WCF service that carries out a simple operation:

[OperationContract]
DoSomething (Stuff input);

If an exception occurs inside DoSomething then a FaultException will be returned. Given that all the client needs to know is whether something went wrong, would you say that there's no need to define a FaultException in this scenario?

like image 896
Mark 909 Avatar asked Oct 12 '22 09:10

Mark 909


1 Answers

It is always good practice to return a FaultException, since if you do not, the channel will be faulted and cannot be used again.

The decision what information need to be sent to the client is taken in the configuration (in service behaviour):

         <serviceBehaviors>
                <behavior name="myName">
                     <serviceDebug includeExceptionDetailInFaults="true" />
       // ....

In fact I always implement IErrorHandler behaviour on the service to catch all exceptions and return FaultException<T> so that I do not have to do it in all my operations.

like image 137
Aliostad Avatar answered Oct 15 '22 10:10

Aliostad