我有几个WCF服务合同,所有这些合同都包含完全相同的方法StopOperation,具有相同的签名: [ServiceContract]public interface IMyServiceA{ [FaultContract(typeof(ServiceAError))] [OperationContract] void StopOperation(
[ServiceContract] public interface IMyServiceA { [FaultContract(typeof(ServiceAError))] [OperationContract] void StopOperation(TaskInformation taskInfo); // other specific methods }
我希望能够做的是将StopOperation提取到接口,IStoppable,并让我的所有服务继承此操作.但是,我遇到了FaultContract定义的问题,因为它定义了具体的故障类型.
是否有可能让FaultContract引用一个抽象的ErrorBase类型,并具有KnownContract指定的具体方法?有一些像:
[ServiceContract] public interface IStoppable { [FaultContract(typeof(ErrorBase))] [OperationContract] void StopOperation(TaskInformation taskInfo); }
无论我在哪里尝试指定KnownContract,它似乎都没有.
你尝试过使用泛型吗?例如:
[ServiceContract] public interface IStoppable<T> where T : ErrorBase { [FaultContract(typeof(T))] [OperationContract] void StopOperation(TaskInformation taskInfo); }
然后你会说
[ServiceContract] public interface IMyServiceA : IStoppable<ServiceAError> { // other specific methods }
没有测试过这个,但我没有看到为什么这不起作用的任何理由.