I have a simple WCF service that carries out a simple operation:
我有一个简单的WCF服务,执行一个简单的操作:
[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?
如果DoSomething内部发生异常,则会返回一个FaultException。考虑到客户需要知道的是是否出了问题,您是否认为在这个场景中没有必要定义FaultException ?
1 个解决方案
#1
4
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.
实际上,我总是在服务上实现IErrorHandler行为来捕获所有异常并返回FaultException
#1
4
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.
实际上,我总是在服务上实现IErrorHandler行为来捕获所有异常并返回FaultException