Search code examples
soapwsdlsoapui

How does a SOAP WS know the requested operation?


Say my WSDL contains the following:

<message name="modifRequest">
    <part name="siList" element="sn:siListElement"/>
</message>
<message name="modifResponse">
    <part name="siList" element="sn:boolElement"/>
</message>

<portType name="siModificationPortType">
    <operation name="delete">
        <input message="tns:modifRequest" />
        <output message="tns:modifResponse" />
    </operation>
    <operation name="update">
        <input message="tns:modifRequest" />
        <output message="tns:modifResponse" />
    </operation>
</portType>

Which generates the following SOAP client message in SoapUI, whether in an update or a delete request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"         xmlns:sim="simSchema">
   <soapenv:Header/>
<soapenv:Body>
  <sim:siListElement>
     <!--1 or more repetitions:-->
     <sim:si name="?" desc="?" workspace="workspace">
        <!--Zero or more repetitions:-->
        <sim:bp name="?" value="?" bps="?"/>
     </sim:si>
  </sim:siListElement>

So it seems that the only thing sent through HTTP to the WS is the siListElement. But how does the WS know the operation the client wants to reach (here, delete/update)? Especially in that case where the inputs of both operations have the same structure.


Solution

  • The WS know the operation through SOAPAction HTTP Header. When you create a new SOAP Test request in SOAPUI you have to select the operation and choosing it then SOAPUI automatically sets the operation for you request an maps this operation to the necessary SOAPAction which it will send as HTTP header when you run the test request.

    This "magic" happens because in your WSDL surely there is also a information which you are missing in your question which is binding the wsdl:operation against soap:operation. In your WSDL probably there are something like:

    <binding name="bindingDelete" type="siModificationPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="delete">
            <soap:operation soapAction="delete"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    
    <binding name="bindingAdd" type="siModificationPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="add">
            <soap:operation soapAction="add"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    

    So when you specify to SOAPUI that your operation is delete then SOAPUI is sending SOAPAction http header with the correct value like for example delete, instead of you specify add operation then SOAPAction http header with some value like add is send.

    You can check what I'm saying runing your request and clicking on the Raw tab on the left side of your SOAPRequest and checking the different SOAPAction values for your operation types:

    enter image description here

    Hope this helps,