2

Visual Studio 11 の「サービス リファレンス」を介して、C# で Web サービスを使用しているときに、非常に厄介な問題に直面しています。

呼び出しを行い、Web サービスから (別のドメインで) 応答を取得することはできますが、応答の処理中にエラーが表示されます。

タイプ 'System.Xml.XmlNode[]' のオブジェクトをタイプ ComplexType_Client_InformationResponse にキャストできません

これがwsdlです:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="https://xxx.fr/client/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="Service_Client" targetNamespace="https://xxx.fr/client/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <xsd:schema targetNamespace="https://xxx.fr/client/">
      <xsd:complexType name="ComplexType_Client_InformationIn">
        <xsd:all>
          <xsd:element name="PARAM1" type="xsd:string" />
          <xsd:element name="PARAM2" type="xsd:string" />
        </xsd:all>
      </xsd:complexType>
      <xsd:complexType name="ComplexType_Client_InformationResponse">
        <xsd:all>
          <xsd:element name="ELEMENT1" type="xsd:int" />
          <xsd:element name="ELEMENT2" nillable="true" type="xsd:string" />
          <xsd:element name="ELEMENT3" nillable="true" type="xsd:string" />
          <xsd:element name="ELEMENT4" nillable="true" type="xsd:string" />
          <xsd:element name="ELEMENT5" nillable="true" type="xsd:string" />
        </xsd:all>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="informationXIn">
    <wsdl:part name="informationIn" type="tns:ComplexType_Client_InformationIn" />
  </wsdl:message>
  <wsdl:message name="informationXOut">
    <wsdl:part name="return" type="tns:ComplexType_Client_InformationResponse" />
  </wsdl:message>
  <wsdl:portType name="Service_ClientPort">
    <wsdl:operation name="informationX">
      <documentation>@param ComplexType_Client_InformationIn $informationIn</documentation>
      <wsdl:input message="tns:informationXIn" />
      <wsdl:output message="tns:informationXOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="Service_ClientBinding" type="tns:Service_ClientPort">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
    <wsdl:operation name="informationX">
      <soap:operation soapAction="https://xxx.fr/client/#informationX" />
      <wsdl:input>
        <soap:body use="encoded" namespace="https://xxx.fr/client/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="encoded" namespace="https://xxx.fr/client/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Service_ClientService">
    <wsdl:port name="Service_ClientPort" binding="tns:Service_ClientBinding">
      <soap:address location="https://xxx.fr/client/" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

...そして応答:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns1="https://xxx.fr/client" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:informationXResponse>
      <return xsi:type="SOAP-ENC:Struct">
        <ELEMENT1 xsi:type="xsd:int">697438</ELEMENT1>
        <ELEMENT2 xsi:type="xsd:string">DDDD</ELEMENT2>
        <ELEMENT3 xsi:type="xsd:string">CCCC</ELEMENT3>
        <ELEMENT4 xsi:type="xsd:string">VVVVV</ELEMENT4>
        <ELEMENT5 xsi:nil="true"/>
      </return>
    </ns1:informationXResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Fiddler を使って、返された XML の変更を開始し、置換すると機能するようになりました

<return xsi:type="SOAP-ENC:Struct">

<return>
4

0 に答える 0