how to set a default faultcontract attribute in wcf-service
is there a way to set a "default"-faultcontract e.g. for all methods in a wcf-service-class? like
[ServiceContract]
[DefaultFaultContract(typof(MyServiceFault))]
class MyService
{
[OperationContract]
开发者_如何转开发 void DoWork();
}
instead of:
[ServiceContract]
public interface ICustomerService
{
[OperationContract]
[FaultContract(typeof(ServiceFault))]
void DoWork();
}
I appreciate a link for a "Step-By-Step" Guide.
This might not be the "right" way to do this, but I just posted an answer on another question
This code might be usefull to you
It builds a proxy which catches every exception that occured when calling members of an object implementing a specific interface. You could use this on wpf channels.
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
You could rewrite a bit this class to have the kind of behavior you want (like not rethrowing the exception on error and returning null -if function is not returning void-)
精彩评论