SOAP requests in .NET

前端 未结 1 1980
梦如初夏
梦如初夏 2020-12-20 17:52

We\'re trying to use SOAP requests to interact with a booking API using Visual Studio C#.

We\'ve interfaced with a Web Service of another API without issue but this

相关标签:
1条回答
  • 2020-12-20 18:34

    You are trying to consume an RPC-literal service from .NET, so you may have to convert the service to doc-literal. See MSDN Blog.

    EDIT: More complete answer

    The goal is to be able to use doc-literal, but still send the same message. Let's focus on the ping operation. Right now your WSDL has the type defined as:

    <complexType name="HRSPingRequest">
        <complexContent>
            <extension base="tns:HRSRequest">
                <sequence>
                    <element name="echoData" type="xsd:string"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    

    And your message defined as:

    <message name="HRSSoapService_pingRequest">
        <part name="pingRequest" type="tns:HRSPingRequest"/>
    </message>
    

    And your binding defined as:

    <binding name="HRSSoapServiceBinding" type="tns:HRSSoapService">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="ping">
            <soap:operation soapAction=""/>
            <input>
                <soap:body namespace="com.hrs.soap.hrs" use="literal"/>
            </input>
            <output>
                <soap:body namespace="com.hrs.soap.hrs" use="literal"/>
            </output>
            <fault name="HRSException">
                <soap:fault name="HRSException" use="literal"/>
            </fault>
        </operation>
    </binding>
    

    So locally we change the "rpc" to "document" and then fix the WSDL to actual document/literal:

    <element name="ping" type="tns:HRSPingRequestWrapper" />
    <complexType name="HRSPingRequestWrapper">
        <sequence>
            <element name="pingRequest" type="tns:HRSPingRequest" />
        </sequence>
    </complexType>
    <complexType name="HRSPingRequest">
        <complexContent>
            <extension base="tns:HRSRequest">
                <sequence>
                    <element name="echoData" type="xsd:string"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    
    ...
    
    <message name="HRSSoapService_pingRequest">
        <part name="pingRequest" element="tns:ping"/>
    </message>
    

    Now generate off of this WSDL and see if it sends a ping request. If you don't fix the Response structure, it may not understand what comes back, but you should at least see a request sent out over the wire. You can use SoapUI to load both WSDLs and see what kind of requests are generated. The goal is to send the same request, just using document/literal instead of rpc/literal.

    0 讨论(0)
提交回复
热议问题