在尝试使用声明类型数组的 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 自动生成其客户端代理代码而没有任何错误。
更改自动生成代码不是一个可行的解决方案,如果您能发现可能导致这支雪茄的原因。