我有几个 WCF 服务合约,所有合约都包含完全相同的方法 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
}
尚未对此进行测试,但我看不出有任何理由不这样做。
关于wcf - 故障契约继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13862875/