开发者

When to use WCF Fault Exception

开发者 https://www.devze.com 2023-02-21 23:32 出处:网络
I have a simple WCF service that carries ou开发者_高级运维t a simple operation: [OperationContract]

I have a simple WCF service that carries ou开发者_高级运维t 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消