2011-09-16 147 views
3

是否有设置“default”-faultcontract的方法,例如对于wcf-service-class中的所有方法? 像如何在wcf-service中设置默认的faultcontract属性

[ServiceContract] 
[DefaultFaultContract(typof(MyServiceFault))] 
class MyService 
{ 
    [OperationContract] 
    void DoWork(); 
} 

代替:

[ServiceContract] 
public interface ICustomerService 
{ 
    [OperationContract] 
    [FaultContract(typeof(ServiceFault))] 
    void DoWork(); 
} 

我很欣赏一个链接,一个 “一步一步” 指南。

回答

0

这可能不是“正确”的方式做到这一点,但我只是张贴在another question

This code might be usefull to you

回答它建立其捕获每个异常调用对象的成员时,所发生的代理实现特定的界面。 你可以在wpf频道上使用它。

IMyInterface myService = [...]; 
IMyInterface myExceptionLoggedService = ExceptionProxyGenerator.Generate<IMyInterface>(myService); 
(myExceptionLoggedService as IExceptionProxy).Error+=(sender,method,exception)=>{ 
    // do what you want on exception 
}; 
// Use my service : 
myExceptionLoggedService.MyOkFunction();// ok 
myExceptionLoggedService.MyExceptionFunction();// calling the above delegate 

你可以重写了一下这个类有你想要的那种行为(如不重新抛出的错误异常,并返回空 - 如果函数没有返回无空隙)

相关问题