【问题标题】:How does a SOAP WS know the requested operation?SOAP WS 如何知道请求的操作?
【发布时间】:2014-10-14 04:13:43
【问题描述】:

假设我的 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 怎么知道客户端想要达到的操作(这里是删除/更新)?尤其是在两个操作的输入具有相同结构的情况下。

【问题讨论】:

    标签: soap wsdl soapui


    【解决方案1】:

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

    之所以会发生这种“魔术”,是因为在您的 WSDL 中肯定还有一个您在问题中缺少的信息,它将wsdl:operationsoap: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 值:

    希望这会有所帮助,

    【讨论】:

    猜你喜欢
    • 2011-11-27
    • 2021-08-19
    • 1970-01-01
    • 2023-02-01
    • 1970-01-01
    • 2015-11-15
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多