Alex Rivera | Logout

SOAP requests in .NET

Asked 2012-08-03T12:50:15.423
8

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 one is proving problematic.

We've added it as a Service Reference and Visual Studio has generated all the classes for it and web.config entries so that all seems well.

However when we try and make a simple request to the client SOAP Service we get the following error:

Namespace='com.hrs.soap.hrs' is not supported with rpc\literal SOAP. The wrapper element has to be unqualified.

The code is:

PingRequest pingrequest = new PingRequest();    
SoapServiceClient service = new SoapServiceClient();
service.ping(pingrequest);

This what's been added in the Web.config file:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HRSSoapServiceBinding" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="..."
          binding="basicHttpBi
Edit
Report

1 Answer

6

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:HRSPingRe
answered 2012-08-03T13:01:17.210

Your Answer