为什么没有SOAPAction的SOAP请求甚至信封中的操作名称仍然有效?

时间:2014-10-30 06:53:46

标签: soap

我遇到了一件奇怪的事: 我将SOAP请求发送到SOAP服务提供者,SOAP请求信封没有SOAPAction头,并且正文中没有操作名称。但反应仍然可以。 这是我的WSDL

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:com.tung.switchyard:soap-hello:1.0" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="IHello" targetNamespace="urn:com.tung.switchyard:soap-hello:1.0">
  <wsdl:types>
<xs:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:com.tung.switchyard:soap-hello:1.0" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="urn:com.tung.switchyard:soap-hello:1.0" version="1.0">
<xs:element name="greetingResponse" type="tns:greetingResponse"/>
<xs:element name="person" type="tns:person"/>
<xs:complexType name="person">
    <xs:sequence>
      <xs:element minOccurs="0" name="name" type="xs:string"/>
      <xs:element name="sex" type="xs:boolean"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="greetingResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="response" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
            <xs:element name="NewOperation">
                <xs:complexType>
                    <xs:sequence>

                        <xs:element name="in" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="NewOperationResponse">
                <xs:complexType>
                    <xs:sequence>

                        <xs:element name="out" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
</xs:schema>
  </wsdl:types>
  <wsdl:message name="hello">
    <wsdl:part element="tns:person" name="arg0">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="NewOperationRequest">
    <wsdl:part element="tns:person" name="argo">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="helloResponse">
    <wsdl:part element="tns:greetingResponse" name="return">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="NewOperationResponse">
    <wsdl:part element="tns:greetingResponse" name="return">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="IHelloPortType">
    <wsdl:operation name="hello">
      <wsdl:input message="tns:hello" name="hello">
    </wsdl:input>
      <wsdl:output message="tns:helloResponse" name="helloResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="NewOperation">
      <wsdl:input message="tns:NewOperationRequest">
    </wsdl:input>
      <wsdl:output message="tns:NewOperationResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="IHelloSoapBinding" type="tns:IHelloPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="hello">
      <soap:operation soapAction="hello" style="document"/>
      <wsdl:input name="hello">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="helloResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="NewOperation">
      <soap:operation soapAction="NewOperation" style="document"/>
      <wsdl:input name="NewOperationRequest">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="NewOperationResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="IHello">
    <wsdl:port binding="tns:IHelloSoapBinding" name="IHelloPort">
      <soap:address location="http://localhost:8080/soap-hello/IHello"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

请求信封

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:com.tung.switchyard:soap-hello:1.0">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:person>
         <name>John</name><sex>true</sex>
      </urn:person>
   </soapenv:Body>
</soapenv:Envelope>

响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
   <soap:Body>
      <greetingResponse xmlns="urn:com.tung.switchyard:soap-hello:1.0">
         <response>Hello John</response>
      </greetingResponse>
   </soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:1)

在您的WSDL文件中,您已经提到了两个服务的soap action属性,并且这两个服务都具有相同的请求和响应元素。 SOAP Action属性在Http Post Header中发送。当您在没有SOAP Action的情况下发送它时,它将失败。我已经执行了测试,下面是日志。

没有SOAP操作

POST /DemoWS/services/IHello HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8080
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 375

Request Envelope

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><person xmlns="urn:com.tung.switchyard:soap-hello:1.0"><name xmlns="">Test</name><sex xmlns="">true</sex></person></soapenv:Body></soapenv:Envelope>

Error Response Envelope

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><axis2ns2:Fault xmlns:axis2ns2="http://schemas.xmlsoap.org/soap/envelope/"><faultcode>axis2ns2:Client</faultcode><faultstring>The endpoint reference (EPR) for the Operation not found is http://localhost:8080/DemoWS/services/IHello and the WSA Action = . If this EPR was previously reachable, please contact the server administrator.</faultstring><detail/></axis2ns2:Fault></soapenv:Body></soapenv:Envelope>

使用SOAP Action - 它可以正常运行

POST /DemoWS/services/IHello HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8080
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: "NewOperation"
Content-Length: 375

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><person xmlns="urn:com.tung.switchyard:soap-hello:1.0"><name xmlns="">Test</name><sex xmlns="">true</sex></person></soapenv:Body></soapenv:Envelope>