SOAP WS如何知道请求的操作?

SOAP WS如何知道请求的操作?,soap,wsdl,soapui,Soap,Wsdl,Soapui,假设我的WSDL包含以下内容: <message name="modifRequest"> <part name="siList" element="sn:siListElement"/> </message> <message name="modifResponse"> <part name="siList" element="sn:boolElement"/> </message> <portTy

假设我的WSDL包含以下内容:

<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>

它在SoapUI中生成以下SOAP客户端消息,无论是在更新还是删除请求中:

<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>


因此,似乎唯一通过HTTP发送到WS的东西就是
siListElement
。但是WS如何知道客户端想要达到的操作(这里是delete/update)?特别是在两个操作的输入具有相同结构的情况下。

WS通过
SOAPAction
HTTP头知道操作。当您在SOAPUI中创建一个新的SOAP测试请求时,您必须选择操作并选择它,然后SOAPUI会自动为您的请求设置操作,并将此操作映射到必要的
SOAPAction
,当您运行测试请求时,它将作为HTTP头发送

之所以会出现这种“魔力”,是因为在您的WSDL中,您的问题中肯定还缺少一个信息,即将
WSDL:operation
绑定到
soap:operation
。在您的WSDL中可能有如下内容:

<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>

因此,当您向SOAPUI指定您的操作是delete时,SOAPUI将发送
SOAPAction
http头,其中包含正确的值,例如
delete
,而不是指定add操作,然后发送
SOAPAction
http头,其中包含一些值,例如
add

您可以在运行请求并单击SOAPRequest左侧的
Raw
选项卡时检查我所说的内容,并为您的操作类型检查不同的
SOAPAction
值:


希望这能有所帮助,

显然SOAP1.2没有这样的标题,而是使用内容类型标题,并辅以“操作”信息,请参阅