WCF Contract first:complexType 已经声明

WCF Contract first: complexType has already been declared

我正在使用 svcutil.exe 根据来自外部源的合同生成服务端点。

它似乎按预期工作,但该服务无法向其他人公开端点。

具体来说,当我尝试获取服务的 WSDL 时,抛出异常并出现以下错误:

System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.XmlSerializerOperationBehavior contract: http://tempuri.org/xml/wsdl/soap11/DistributionService/1/port:DistributionReceiverWebServicePort ----> System.Xml.Schema.XmlSchemaException: The complexType 'http://tempuri.org/xml/wsdl/soap11/DistributionService/1/types:FejlType' has already been declared.

但是 - 类型 FejlType 类型只声明一次并且非常简单 class:

[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tempuri.org/xml/wsdl/soap11/DistributionService/1/types")]
[System.Runtime.Serialization.DataContractAttribute(Name = "FejlType", Namespace = "http://tempuri.org/xml/wsdl/soap11/DistributionService/1/types")]
public class FejlType : object, System.Runtime.Serialization.IExtensibleDataObject
{
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    private string FejlKodeField;
    private string FejlTekstField;

    public System.Runtime.Serialization.ExtensionDataObject ExtensionData
    {
        get {return this.extensionDataField;}
        set {this.extensionDataField = value;}
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired = true, EmitDefaultValue = false)]
    public string FejlKode
    {
        get {return this.FejlKodeField;}
        set {this.FejlKodeField = value;}
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired = true, EmitDefaultValue = false)]
    public string FejlTekst
    {
        get {return this.FejlTekstField;}
        set {this.FejlTekstField = value;}
    }
}

我完全一头雾水 - 为什么 WCF 在导出 WSDL 时会抱怨这个?

我找到了问题的原因。

仅供参考:WSDL 源自 KOMBIT(丹麦政府的 IT-thingy),WSDL 是其数据中心 (Serviceplatformen) 的一部分

我发现 svcutil.exe 生成的服务 类 实现了类型 FejlType 两次 - 顺便说一句,都是部分 类。其中一个具有特定的 .net 命名空间前缀,另一个没有自己的前缀。导致问题的原因是类型上的 XmlTypeAttribute - 它们中的每一个都暴露相同的 xml 名称空间。因此,即使服务 类 确实编译了,它们也公开了相同的 xml 类型规范 - 导致我在此处报告的异常。