wcf - 故障契约继承

标签 wcf inheritance datacontract

我有几个 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/

相关文章:

wcf - 有谁知道使用 WCF 为非 .NET 客户端公开 SOAP 接口(interface)的任何问题?

wcf - 对 WCF 服务进行版本控制的方法

wcf - 自定义 SOAP 错误具有错误的命名空间 http ://schemas. datacontract.org/2004/07/

c# - Parent - C# 中的 CChild 管理

c# - CollectionDataContract序列化未添加自定义属性(DataMember)

wcf - 通过WCF传递匿名类型的实例

.net - 如何在 ServiceStack.Text 中使用 EnumMember 属性反序列化可空枚举?

asp.net - 在 DMZ 中运行安全 WCF 服务时出现问题

function - 接收 NFT 并发送代币进行交换的金库,反之亦然

子类中的 Java 静态构造函数访问