如何使用WCF错误契约全球,而不必指定在操作层面?契约、如何使用、层面、而不必

2023-09-04 23:28:02 作者:给不了你嫁衣绝不碰你内衣

我需要从一个WCF服务返回的特定类型的故障,使客户端能够捕获的FaultException< MyClass的> 。为了做到这一点,因为据我所知,唯一的出路就是应用 FaultContract(typeof运算(MyClass的))在操作层面。是否有任何其他方式在全球范围内做到这一点?一个地方,我可以在所有服务中添加此合同的所有操作?

I need to return a fault of specific type from a WCF service so that the client can catch FaultException<MyClass>. In order to do this, as far as I know, only way out is to apply the FaultContract(typeof(MyClass)) at the operation level. Is there any other way to do this at a global level? One place where I can add this contract to all operations in all services?

推荐答案

不幸的是,你需要在每一个操作添加它,但是你可以使用工具,如的 PostSharp 将重新写编译code,所以你可以创建你把一个合同,并有PostSharp添加正确的 FaultContract 每个属性 OperationContract的

Unfortunately you need to add it at every operation, however you can use tools like PostSharp that will re-write your code on compile so you could create an attribute that you put on a contract and have PostSharp add the correct FaultContract attribute on each OperationContract.

 
精彩推荐