.NET没有反序列化XSD maxOccurs =“unbounded”元素

时间:2012-11-12 18:14:59

标签: .net serialization xsd wsdl

在尝试使用声明类型数组的WSDL时,.NET无法反序列化响应消息。

WSDL

https://docs.google.com/open?id=0B5Se_xHASR2LS0EtdmxfNGZWMTg

自动生成的客户端代理

Visual Studio为此服务操作响应消息创建以下定义。

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetServiceRequestSummariesMatchingProfileResponse", WrapperNamespace="http://www.acme.com/webservices/connectors/731/servicerequest/message" +
    "types", IsWrapped=true)]
public partial class GetServiceRequestSummariesMatchingProfileResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.acme.com/schema/uniform/731/servicerequest/sr/srtypes", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("ServiceRequestSummary")]
    public ServiceRequestSummaryType[] ServiceRequestSummary;

    public GetServiceRequestSummariesMatchingProfileResponse() {
    }

    public GetServiceRequestSummariesMatchingProfileResponse(ServiceRequestSummaryType[] ServiceRequestSummary) {
        this.ServiceRequestSummary = ServiceRequestSummary;
    }
}

这不起作用,并且序列化程序无法对ServiceRequestSummaryType []中的ServiceRequestSummaryType对象进行反序列化,因此无论响应是否包含它们,它始终为空。

响应SOAP消息

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"></s:Header>
    <soap:Body>
        <GetServiceRequestSummariesMatchingProfileResponse xmlns="http://www.acme.com/webservices/connectors/731/servicerequest/messagetypes">
            <ServiceRequestSummary xmlns="http://www.acme.com/schema/uniform/731/servicerequest/sr/srtypes">
                <ServiceRequestIdentification>
                    <ServiceRequestTechnicalKey>MD2P24BENM001</ServiceRequestTechnicalKey>
                    <ReferenceValue>12/00056/SR</ReferenceValue>
                    <AlternativeReferences>
                        <AlternativeReference xmlns="http://www.acme.com/schema/uniform/72b/common/uniformtypes">
                            <ReferenceValue>ssa</ReferenceValue>
                            <ReferenceType>FIRM</ReferenceType>
                        </AlternativeReference>
                    </AlternativeReferences>
                </ServiceRequestIdentification>
                <SiteLocation>
                    <Address>                       </Address>
                    <UPRN></UPRN>
                </SiteLocation>
                <NatureOfComplaint>Test</NatureOfComplaint>
                <AdministrationDetails>
                    <RequestTypeCode>DFOUL</RequestTypeCode>
                    <RequestTypeText>Dog fouling</RequestTypeText>
                    <RequestKindCode>D</RequestKindCode>
                    <RequestKindText>Dog Request</RequestKindText>
                    <AllocatedToCode>EHCALL</AllocatedToCode>
                    <AllocatedToText></AllocatedToText>
                    <TimeAllocated></TimeAllocated>
                    <AllocationHistory>
                        <AllocationHistoryDetail>
                            <OfficerCode>EHCALL</OfficerCode>
                            <OfficerName>EH Call Centre</OfficerName>
                            <AllocationDateTime>2012</AllocationDateTime>
                        </AllocationHistoryDetail>
                    </AllocationHistory>
                    <HowReceivedCode>TELE</HowReceivedCode>
                    <HowReceivedText>telephone</HowReceivedText>
                    <TimeReceived>2012-11-02T13:40:00</TimeReceived>
                    <StatusCode>1_NEW</StatusCode>
                    <StatusText>1_NEW - New Request</StatusText>
                </AdministrationDetails>
                <SubjectDetails>
                    <SubjectContactDetails></SubjectContactDetails>
                </SubjectDetails>
                <RequestType>DOG</RequestType>
                <RequestKindCode>D</RequestKindCode>
                <RequestKindText>Dog Request</RequestKindText>
            </ServiceRequestSummary>
        </GetServiceRequestSummariesMatchingProfileResponse>
        <TransactionReport xmlns="">
            <TransactionComplete>True</TransactionComplete>
            <TransactionSuccess>True</TransactionSuccess>
            <TransactionMessages></TransactionMessages>
        </TransactionReport>
    </soap:Body>
</soap:Envelope>

然而,在网上打猎之后,我注意到了类似的东西,但没有任何解释。如果我更改自动生成的代码以包含命名空间;

如此绝对

[System.Xml.Serialization.XmlElementAttribute("ServiceRequestSummary")]

我们有

[System.Xml.Serialization.XmlElementAttribute("ServiceRequestSummary", Namespace = "http://www.acme.com/schema/uniform/731/servicerequest/sr/srtypes")]

然后它会起作用。我不明白WSDL或使反序列化失败的响应消息有什么问题,所有VS自动从WSDL生成其客户端代理代码后没有任何错误。

更改自动生成代码不是一个可行的解决方案,如果你能发现可能导致雪茄的原因。

1 个答案:

答案 0 :(得分:0)

根据XMLSpy,此WSDL无效:

File C:\Temp\Untitled1.wsdl is not valid.
    Invalid XML schema: ''s4:ServiceRequestIdentificationType' must refer to an existing simple or complex type.'
        Error location: wsdl:definitions / wsdl:types / s:schema / s:complexType / s:sequence / s:element / @type

您是如何生成代理的? SvcUtil工具?如果是这样,那么您需要在命令行上提供所有 XML Schema文件的路径。