有没有办法为wcf--faultcontract-class中的所有方法设置一个“默认”服务?喜欢
[ServiceContract]
[DefaultFaultContract(typof(MyServiceFault))]
class MyService
{
[OperationContract]
void DoWork();
}而不是:
[ServiceContract]
public interface ICustomerService
{
[OperationContract]
[FaultContract(typeof(ServiceFault))]
void DoWork();
}我很感谢有"Step-By-Step“指南的链接。
发布于 2011-09-16 16:52:21
这可能不是做这件事的“正确”方法,但我刚刚在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你可以稍微重写一下这个类,使其具有你想要的行为(比如在出错时不重新抛出异常,返回null -if函数不会返回空-)
https://stackoverflow.com/questions/7442074
复制相似问题