Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在wcf服务中设置默认faultcontract属性_C#_Wcf_Exception Handling - Fatal编程技术网

C# 如何在wcf服务中设置默认faultcontract属性

C# 如何在wcf服务中设置默认faultcontract属性,c#,wcf,exception-handling,C#,Wcf,Exception Handling,是否有一种方法可以设置“默认”-faultcontract,例如为wcf服务类中的所有方法设置? 像 而不是: [ServiceContract] public interface ICustomerService { [OperationContract] [FaultContract(typeof(ServiceFault))] void DoWork(); } 我很感激能有一个“分步”指南的链接。这可能不是一个“正确”的方法,但我刚刚在网站上发布了一个答案 它构

是否有一种方法可以设置“默认”-faultcontract,例如为wcf服务类中的所有方法设置? 像

而不是:

[ServiceContract]
public interface ICustomerService
{
    [OperationContract]
    [FaultContract(typeof(ServiceFault))]
    void DoWork();
}
我很感激能有一个“分步”指南的链接。

这可能不是一个“正确”的方法,但我刚刚在网站上发布了一个答案

它构建了一个代理,用于捕获在调用实现特定接口的对象的成员时发生的所有异常。 你可以在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
IMyInterface myService=[…];
IMyInterface myExceptionLoggedService=ExceptionProxyGenerator.Generate(myService);
(myExceptionLoggedService作为IEExceptionProxy)。错误+=(发送方、方法、异常)=>{
//在例外情况下做你想做的事
};
//使用我的服务:
myExceptionLoggedService.MyOkFunction();//好啊
myExceptionLoggedService.MyExceptionFunction();//呼叫上述代表
您可以稍微重写这个类,使其具有所需的行为(例如,如果函数不返回void-,则不在出错时重新引发异常并返回null-)

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