使用XmlSerializer和使用RPC Literal的Soap在WCF上解包响应

时间:2013-04-20 02:35:33

标签: xml wcf soap wsdl svcutil.exe

我正在尝试使用WCF使用Soap 1.1 Web服务。在使用wsdl定义的svcutil生成代理后,我发现所有响应都为null。

该服务似乎使用RPC Literal,因此WCF回退到使用XmlSerializer。这是wsdl的定义:

<wsdl:definitions xmlns:typens="http://www.myservice.es/Schemas" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.myservice.es/Schemas">

<wsdl:types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.myservice.es/Schemas">
        <xsd:include schemaLocation="../xsd/myservicetypes.xsd"/>           
    </xsd:schema>
</wsdl:types>
<message name="serviceRequest"/>
<message name="serviceResponse">
    <part name="serviceReturn" type="typens:DateTimeResponse"/>
</message>
<portType name="QueryServiceDateTimePort">
    <operation name="QueryServiceDateTime">
        <input message="typens:serviceRequest"/>
        <output message="typens:serviceResponse"/>
    </operation>
</portType>
<binding name="QueryServiceDateTimeBinding" type="typens:QueryServiceDateTimePort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="QueryServiceDateTime">
        <soap:operation soapAction="urn:QueryServiceDateTime"/>
        <input>
            <soap:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.myservice.es/Schemas"/>
        </input>
        <output>
            <soap:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.myservice.es/Schemas"/>
        </output>
    </operation>
</binding>
<service name="QueryServiceDateTimeService">
    <port name="QueryServiceDateTimePort" binding="typens:QueryServiceDateTimeBinding">
        <soap:address location="https://www.tests.com"/>
    </port>
</service>

但是,该服务会返回此响应:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <serviceResponse>
         <serviceReturn>
            <DateTime v="2013-04-20T01:13:22.001" xmlns="http://www.myservice.es/Schemas"/>
         </serviceReturn>
      </serviceResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

WCF和SoapUI都期望和QueryServiceDateTimeResponse之前或serviceResponse之前的元素,因此它们无法反序列化或验证响应。

如何让WCF重新审核此响应并对其进行反序列化?无论如何我可以标记代理来打开该元素吗?

我应该注意,在这种情况下我不能使用MessageContract,因为它与RPC-Literal不兼容。

1 个答案:

答案 0 :(得分:0)

正如我在这篇文章中发现的那样(http://msdn.microsoft.com/en-us/library/ms996466.aspx),你可能会切换到文档 - 文字。