2011-09-16 149 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 

你可以重寫了一下這個類有你想要的那種行爲(如不重新拋出的錯誤異常,並返回空 - 如果函數沒有返回無空隙)

相關問題