When to use WCF Fault Exception

a 夏天 提交于 2019-12-23 11:54:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5514470/when-to-use-wcf-fault-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!