首页 > 解决方案 > 带有继承类的 C#/WCF 中的 XML 序列化错误

问题描述

我有一个 web 服务给定的 WSDL 模式,我必须构建一个 WCF 发送器才能使用该服务。生成和构建工作正常。不幸的是,在开始传输时出现错误:

命名空间“ http://www.mycompany.com/schema/oac ”中的顶部 XML 元素“RequestContext”引用了不同的类型 RequestContextBaseType 和 RequestContextType。使用 XML 属性为元素或类型指定另一个 XML 名称或命名空间。

让我们看一下显示问题的示例界面:

WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
    xmlns:oas="http://www.mycompany.com/schema/oacs"
    xmlns:oast="http://www.mycompany.com/schema/oacst"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        name="OrgaAuthService"
        targetNamespace="http://www.mycompany.com/schema/oacs">

    <wsdl:types>
        <xs:schema>
            <xs:import namespace="http://www.mycompany.com/schema/oacst"
                       schemaLocation="OrgaAuthServiceTypes.xsd"/>
        </xs:schema>
    </wsdl:types>

    <!-- Registration -->
    <wsdl:message name="RegisterOrganizationRequest">
        <wsdl:part name="parameters" element="oast:RegisterOrganization"/>
    </wsdl:message>
    <wsdl:message name="RegisterOrganizationResponse">
        <wsdl:part name="parameters" element="oast:RegisterOrganizationResponse"/>
    </wsdl:message>

    <!-- GetStatusFromRegistration -->
    <wsdl:message name="GetStatusFromOrganizationRegistrationRequest">
        <wsdl:part name="parameters" element="oast:GetStatusFromOrganizationRegistration"/>
    </wsdl:message>
    <wsdl:message name="GetStatusFromOrganizationRegistrationResponse">
        <wsdl:part name="parameters" element="oast:GetStatusFromOrganizationRegistrationResponse"/>
    </wsdl:message>

    <wsdl:portType name="OrganizationAuthenticationPort">
        <wsdl:operation name="RegisterOrganization">
            <wsdl:input message="oas:RegisterOrganizationRequest"/>
            <wsdl:output message="oas:RegisterOrganizationResponse"/>
        </wsdl:operation>
        <wsdl:operation name="GetStatusFromRegisterOrganization">
            <wsdl:input message="oas:GetStatusFromOrganizationRegistrationRequest"/>
            <wsdl:output message="oas:GetStatusFromOrganizationRegistrationResponse"/>
        </wsdl:operation>   
    </wsdl:portType>

    <wsdl:binding name="OrganizationAuthenticationSOAPBinding" type="oas:OrganizationAuthenticationPort">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

        <wsdl:operation name="RegisterOrganization">
            <soap:operation soapAction="" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="OrganizationAuthenticationFault">
                <soap:fault name="OrganizationAuthenticationFault" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>

        <wsdl:operation name="GetStatusFromRegisterOrganization">
            <soap:operation soapAction="" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="OrganizationAuthenticationFault">
                <soap:fault name="OrganizationAuthenticationFault" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>

    </wsdl:binding>

    <wsdl:service name="OrganizationAuthenticationService">
        <wsdl:port name="OrganizationAuthentication" binding="oas:OrganizationAuthenticationSOAPBinding">
            <soap:address
                    location="http://tst.mycompany.com/services/OrganizationAuthentication"/>
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

OrgaAuthServiceTypes.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.mycompany.com/schema/oacst"
    xmlns:iast="http://www.mycompany.com/schema/oacst" xmlns:oac="http://www.mycompany.com/schema/oac"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.0">

    <xs:import namespace="http://www.mycompany.com/schema/oac"
        schemaLocation="OrgaAuth.xsd"/>

    <!-- definitions RegisterOrganization -->
    <xs:element name="RegisterOrganization" type="oac:RegisterOrganizationRequestType"/>
    <xs:element name="RegisterOrganizationResponse" type="oac:RegisterOrganizationResponseType"/>

    <!-- definitions GetStatusFromRegisterOrganization -->
    <xs:element name="GetStatusFromOrganizationRegistration"
        type="oac:GetStatusFromOrganizationRegistrationRequestType"/>
    <xs:element name="GetStatusFromOrganizationRegistrationResponse"
        type="oac:GetStatusFromOrganizationRegistrationResponseType"/>


</xs:schema>

OrgaAuth.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.mycompany.com/schema/oac"
    xmlns:oac="http://www.mycompany.com/schema/oac" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    attributeFormDefault="unqualified" version="0.0">

    <xs:complexType name="RegisterOrganizationRequestType">
        <xs:sequence>
            <xs:element name="RequestContext" type="oac:RequestContextBaseType"/>
            <xs:element name="OrganizationRegistration" type="oac:OrganizationRegistrationType"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="RegisterOrganizationResponseType">
        <xs:sequence>
            <xs:element name="ResponseContext" type="oac:ResponseContextType"/>
            <xs:element name="JobKey" type="oac:JobKeyType"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="GetStatusFromOrganizationRegistrationRequestType">
        <xs:sequence>
            <xs:element name="RequestContext" type="oac:RequestContextType"/>      
            <xs:element name="JobKey" type="oac:JobKeyType"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="GetStatusFromOrganizationRegistrationResponseType">
        <xs:sequence>
            <xs:element name="ResponseContext" type="oac:ResponseContextType"/>            
            <xs:choice>
                <xs:element name="Success" type="xs:string" minOccurs="0"/>
                <xs:element name="Error" type="xs:string" minOccurs="0"/>
            </xs:choice>
            <xs:element name="JobFinished" type="xs:boolean"/>
        </xs:sequence>
    </xs:complexType>

    <!-- shared types -->
    <xs:complexType name="RequestContextBaseType">
        <xs:sequence>
            <xs:element name="CompanyName" type="xs:string"> </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="RequestContextType">
        <xs:complexContent>
            <xs:extension base="oac:RequestContextBaseType">
                <xs:sequence>
                    <xs:element name="RequestID" type="xs:string"> </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="ResponseContextType">
        <xs:sequence>
            <xs:element name="RequestID" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="OrganizationRegistrationType">
        <xs:sequence>
            <xs:element name="Name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

    <!-- simple types -->
    <xs:simpleType name="JobKeyType">
        <xs:restriction base="xs:string">
            <xs:minLength value="10"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="IDType">
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
            <xs:maxLength value="255"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

这会在使用 SvcUtil.exe 生成时生成以下 Reference.cs 类:

//------------------------------------------------------------------------------
// <auto-generated>
//     Dieser Code wurde von einem Tool generiert.
//     Laufzeitversion:4.0.30319.42000
//
//     Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
//     der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------



[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.mycompany.com/schema/oacs", ConfigurationName="OrganizationAuthenticationPort")]
public interface OrganizationAuthenticationPort
{

    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    RegisterOrganizationResponse RegisterOrganization(RegisterOrganizationRequest request);

    // CODEGEN: Der Nachrichtenvertrag wird generiert, da der Vorgang mehrere Rückgabewerte aufweist.
    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    System.Threading.Tasks.Task<RegisterOrganizationResponse> RegisterOrganizationAsync(RegisterOrganizationRequest request);

    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    GetStatusFromRegisterOrganizationResponse GetStatusFromRegisterOrganization(GetStatusFromRegisterOrganizationRequest request);

    // CODEGEN: Der Nachrichtenvertrag wird generiert, da der Vorgang mehrere Rückgabewerte aufweist.
    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    System.Threading.Tasks.Task<GetStatusFromRegisterOrganizationResponse> GetStatusFromRegisterOrganizationAsync(GetStatusFromRegisterOrganizationRequest request);
}

/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RequestContextType))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.mycompany.com/schema/oac")]
public partial class RequestContextBaseType : object, System.ComponentModel.INotifyPropertyChanged
{

    private string companyNameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string CompanyName
    {
        get
        {
            return this.companyNameField;
        }
        set
        {
            this.companyNameField = value;
            this.RaisePropertyChanged("CompanyName");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null))
        {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.mycompany.com/schema/oac")]
public partial class ResponseContextType : object, System.ComponentModel.INotifyPropertyChanged
{

    private string requestIDField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string RequestID
    {
        get
        {
            return this.requestIDField;
        }
        set
        {
            this.requestIDField = value;
            this.RaisePropertyChanged("RequestID");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null))
        {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.mycompany.com/schema/oac")]
public partial class OrganizationRegistrationType : object, System.ComponentModel.INotifyPropertyChanged
{

    private string nameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string Name
    {
        get
        {
            return this.nameField;
        }
        set
        {
            this.nameField = value;
            this.RaisePropertyChanged("Name");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null))
        {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.mycompany.com/schema/oac")]
public partial class RequestContextType : RequestContextBaseType
{

    private string requestIDField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string RequestID
    {
        get
        {
            return this.requestIDField;
        }
        set
        {
            this.requestIDField = value;
            this.RaisePropertyChanged("RequestID");
        }
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="RegisterOrganization", WrapperNamespace="http://www.mycompany.com/schema/oacst", IsWrapped=true)]
public partial class RegisterOrganizationRequest
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public RequestContextBaseType RequestContext;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public OrganizationRegistrationType OrganizationRegistration;

    public RegisterOrganizationRequest()
    {
    }

    public RegisterOrganizationRequest(RequestContextBaseType RequestContext, OrganizationRegistrationType OrganizationRegistration)
    {
        this.RequestContext = RequestContext;
        this.OrganizationRegistration = OrganizationRegistration;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="RegisterOrganizationResponse", WrapperNamespace="http://www.mycompany.com/schema/oacst", IsWrapped=true)]
public partial class RegisterOrganizationResponse
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public ResponseContextType ResponseContext;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public string JobKey;

    public RegisterOrganizationResponse()
    {
    }

    public RegisterOrganizationResponse(ResponseContextType ResponseContext, string JobKey)
    {
        this.ResponseContext = ResponseContext;
        this.JobKey = JobKey;
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.mycompany.com/schema/oac", IncludeInSchema=false)]
public enum ItemChoiceType
{

    /// <remarks/>
    Error,

    /// <remarks/>
    Success,
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetStatusFromOrganizationRegistration", WrapperNamespace="http://www.mycompany.com/schema/oacst", IsWrapped=true)]
public partial class GetStatusFromRegisterOrganizationRequest
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public RequestContextType RequestContext;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public string JobKey;

    public GetStatusFromRegisterOrganizationRequest()
    {
    }

    public GetStatusFromRegisterOrganizationRequest(RequestContextType RequestContext, string JobKey)
    {
        this.RequestContext = RequestContext;
        this.JobKey = JobKey;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetStatusFromOrganizationRegistrationResponse", WrapperNamespace="http://www.mycompany.com/schema/oacst", IsWrapped=true)]
public partial class GetStatusFromRegisterOrganizationResponse
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public ResponseContextType ResponseContext;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute("Error", typeof(string), Namespace="http://www.mycompany.com/schema/oac")]
    [System.Xml.Serialization.XmlElementAttribute("Success", typeof(string), Namespace="http://www.mycompany.com/schema/oac")]
    [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
    public string Item;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=2)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public ItemChoiceType ItemElementName;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.mycompany.com/schema/oac", Order=3)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.mycompany.com/schema/oac")]
    public bool JobFinished;

    public GetStatusFromRegisterOrganizationResponse()
    {
    }

    public GetStatusFromRegisterOrganizationResponse(ResponseContextType ResponseContext, string Item, ItemChoiceType ItemElementName, bool JobFinished)
    {
        this.ResponseContext = ResponseContext;
        this.Item = Item;
        this.ItemElementName = ItemElementName;
        this.JobFinished = JobFinished;
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface OrganizationAuthenticationPortChannel : OrganizationAuthenticationPort, System.ServiceModel.IClientChannel
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class OrganizationAuthenticationPortClient : System.ServiceModel.ClientBase<OrganizationAuthenticationPort>, OrganizationAuthenticationPort
{

    public OrganizationAuthenticationPortClient()
    {
    }

    public OrganizationAuthenticationPortClient(string endpointConfigurationName) : 
            base(endpointConfigurationName)
    {
    }

    public OrganizationAuthenticationPortClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public OrganizationAuthenticationPortClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public OrganizationAuthenticationPortClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress)
    {
    }

    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    RegisterOrganizationResponse OrganizationAuthenticationPort.RegisterOrganization(RegisterOrganizationRequest request)
    {
        return base.Channel.RegisterOrganization(request);
    }

    public ResponseContextType RegisterOrganization(RequestContextBaseType RequestContext, OrganizationRegistrationType OrganizationRegistration, out string JobKey)
    {
        RegisterOrganizationRequest inValue = new RegisterOrganizationRequest();
        inValue.RequestContext = RequestContext;
        inValue.OrganizationRegistration = OrganizationRegistration;
        RegisterOrganizationResponse retVal = ((OrganizationAuthenticationPort)(this)).RegisterOrganization(inValue);
        JobKey = retVal.JobKey;
        return retVal.ResponseContext;
    }

    public System.Threading.Tasks.Task<RegisterOrganizationResponse> RegisterOrganizationAsync(RegisterOrganizationRequest request)
    {
        return base.Channel.RegisterOrganizationAsync(request);
    }

    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    GetStatusFromRegisterOrganizationResponse OrganizationAuthenticationPort.GetStatusFromRegisterOrganization(GetStatusFromRegisterOrganizationRequest request)
    {
        return base.Channel.GetStatusFromRegisterOrganization(request);
    }

    public ResponseContextType GetStatusFromRegisterOrganization(RequestContextType RequestContext, string JobKey, out string Item, out ItemChoiceType ItemElementName, out bool JobFinished)
    {
        GetStatusFromRegisterOrganizationRequest inValue = new GetStatusFromRegisterOrganizationRequest();
        inValue.RequestContext = RequestContext;
        inValue.JobKey = JobKey;
        GetStatusFromRegisterOrganizationResponse retVal = ((OrganizationAuthenticationPort)(this)).GetStatusFromRegisterOrganization(inValue);
        Item = retVal.Item;
        ItemElementName = retVal.ItemElementName;
        JobFinished = retVal.JobFinished;
        return retVal.ResponseContext;
    }

    public System.Threading.Tasks.Task<GetStatusFromRegisterOrganizationResponse> GetStatusFromRegisterOrganizationAsync(GetStatusFromRegisterOrganizationRequest request)
    {
        return base.Channel.GetStatusFromRegisterOrganizationAsync(request);
    }
}

如您所见,架构本身是合法的。问题是来自 RequestContextBaseType 的派生RequestContextType。此错误似乎独立于标记 RequestContext 在 XML 结构中的位置或使用RequestContextTypeRequestContextBaseType的其他位置而发生。它似乎与命名空间有关,并且基类与派生类位于同一命名空间中。

显然必须有一个 XML 属性来解决问题?但是哪一个?我只看到了数组的东西(XmlArrayItem https://msdn.microsoft.com/de-de/library/2baksw0z(v=vs.120).aspx,可能?),但没有解释如何处理“普通”类.

任何想法?

显然,更改命名空间或更改名称是没有问题的,因为这会导致 Web 服务的 XML SOAP 请求无效......


XML 的示例如下所示:

注册机构:

<?xml version="1.0" encoding="UTF-8"?>
<iast:RegisterOrganization xmlns:oac="http://www.mycompany.com/schema/oac"
 xmlns:iast="http://www.mycompany.com/schema/oacst"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.mycompany.com/schema/oacst file:/D:/projects/swissdec/samples/sUA_WCFinterfaceBug_BspExternNeutral/Transmitter/Wcf.Transmitter/Proxy/oa/OrgaAuthServiceTypes.xsd">
    <oac:RequestContext>
        <oac:CompanyName>CompanyName0</oac:CompanyName>
    </oac:RequestContext>
    <oac:OrganizationRegistration>
        <oac:Name>Name0</oac:Name>
    </oac:OrganizationRegistration>
</iast:RegisterOrganization>

GetStatusFromOrganizationRegistration:

<?xml version="1.0" encoding="UTF-8"?>
<iast:GetStatusFromOrganizationRegistration xmlns:oac="http://www.mycompany.com/schema/oac"
 xmlns:iast="http://www.mycompany.com/schema/oacst"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.mycompany.com/schema/oacst file:/D:/projects/swissdec/samples/sUA_WCFinterfaceBug_BspExternNeutral/Transmitter/Wcf.Transmitter/Proxy/oa/OrgaAuthServiceTypes.xsd">
    <oac:RequestContext>
        <oac:CompanyName>CompanyName0</oac:CompanyName>
        <oac:RequestID>RequestID0</oac:RequestID>
    </oac:RequestContext>
    <oac:JobKey>JobKey1111</oac:JobKey>
</iast:GetStatusFromOrganizationRegistration>

标签: c#xmlwcfsoap

解决方案


推荐阅读