简体   繁体   English

PHP并没有Soap动作标题

[英]PHP and no Soap action header

I'm trying to call a remote web service, within my company. 我正试图在我的公司内拨打远程网络服务。 For proprietary reasons I cannot provide the URL to the web service. 出于专有原因,我无法提供Web服务的URL。 The web service has a single function called getItemField. Web服务有一个名为getItemField的函数。 It is a small test service that I'm trying to run PHP against, the service description is as follows: 这是一个小型测试服务,我正在尝试运行PHP,服务描述如下:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://www.oracle.com/ws/MyFirstWebService" xmlns:intf="http://www.oracle.com/ws/MyFirstWebService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://www.w3.org/1999/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.oracle.com/ws/MyFirstWebService">
<!--
WSDL created by Apache Axis version: 1.2alpha Built on Oct 23, 2007 (12:09:54 IST)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.oracle.com/ws/MyFirstWebService">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ArrayOf_xsd_string">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
</restriction>
</complexContent>
</complexType>
</schema>
</wsdl:types>
<message name="getItemFieldRequest">
<part name="args" type="impl:ArrayOf_xsd_string"/>
</message>
<message name="getItemFieldResponse">
<part name="getItemFieldReturn" type="soapenc:string"/>
</message>
<portType name="MyFirstWebService">
<operation name="getItemField" parameterOrder="args">
<input message="impl:getItemFieldRequest" name="getItemFieldRequest"/>
<output message="impl:getItemFieldResponse" name="getItemFieldResponse"/>
</operation>
</portType>
<binding name="MyFirstWebServiceSoapBinding" type="impl:MyFirstWebService">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getItemField">
<wsdlsoap:operation soapAction=""/>
<input name="getItemFieldRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://first" use="encoded"/>
</input>
<output name="getItemFieldResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.oracle.com/ws/MyFirstWebService" use="encoded"/>
</output>
</operation>
</binding>
<service name="MyFirstWebServiceService">
<port binding="impl:MyFirstWebServiceSoapBinding" name="MyFirstWebService">
<wsdlsoap:address location="http://myWebsite.com/services/MyFirstWebService"/>
</port>
</service>
</definitions>

I can connect to the service just fine and print out the name of the single function and type, but when I try to call a function I get 'no SOAPAction header!' 我可以很好地连接到服务并打印出单个函数和类型的名称,但是当我尝试调用函数时,我得到'没有SOAPAction头!' error. 错误。 My PHP code to call the service function is as follows: 我调用服务函数的PHP代码如下:

$options = array(
                // Dev
                'soap_version'=>SOAP_1_2, 
                'exceptions'=>true, 
                'trace'=>1, 
                'cache_wsdl'=>WSDL_CACHE_NONE,
                'features' => SOAP_SINGLE_ELEMENT_ARRAYS,

                // Credentials
                'login' => 'user', 
                'password' => 'pass'
            );        

// Connected successfully
            $client = new SoapClient( "http://myWebsite.com/services/MyFirstWebService?wsdl", $options );

    //Params
        $params = array( '123456' );

        //Options
        $options = array( 'soapaction' => '""' );

        //Call function (Both methods below throw the same 'no SOAPAction header!' error)
        //$result = $client->getItemField( new SoapParam($params, "getItemFieldRequest") );
        $result = $client->__soapCall( "getItemField", array('123456'), $options );

Based on the description of the service it doesn't appear to have a soapaction defined. 根据服务的描述,它似乎没有定义soapaction。 The line I see with soapAction is <wsdlsoap:operation soapAction=""/> . 我用soapAction看到的行是<wsdlsoap:operation soapAction=""/> I tried to specify a blank soapAction since there's none defined, but that didn't seem to work. 我试图指定一个空白的soapAction,因为没有定义,但这似乎不起作用。 Is the web service definition itself incomplete? Web服务定义本身是否不完整? Or am I missing some parameter in my client-side application call? 或者我在客户端应用程序调用中缺少一些参数? Thanks in advance. 提前致谢。

UPDATE: 更新:

Tried to specify the method name as the soap action, but htat didn't work. 试图将方法名称指定为soap操作,但htat不起作用。

    //Params
    $params = array( '123456' );

    //Options
    $options = array( 'soapaction' => 'getItemField' );

    //Call function (STILL THROWS 'no SOAPAction header!')
    $result = $client->__soapCall( "getItemField", $params, $options );

What am I supposed to do if no soapAction is specified in the wsdl, ie if it's set to "". 如果在wsdl中没有指定soapAction,我该怎么办,即如果它设置为“”。

I had a similar issue, but I was using cURL and not the SoapClient , though the solution may be the same. 我有一个类似的问题,但我使用的是cURL而不是SoapClient ,尽管解决方案可能是相同的。

When sending a request to the end service, you have to send a header specifying the Content-Type . 向终端服务发送请求时,您必须发送指定Content-Type的标头。 In this header, you can also specify the action , or "soap action". 在此标题中,您还可以指定action或“soap action”。

$headers = array();
$headers[] = 'Content-Type: application/soap+xml; charset=utf-8; action="[soap action goes here]"';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

In my case, and what appears to be the same as yours, the wsdl lists the following: 在我的情况下,看起来与你的相同,wsdl列出了以下内容:

<wsdl:operation name="getProducts">
    <soap:operation soapAction=""/>
    <!-- trimmed -->
</wsdl:operation>

At first, I see soapAction="" , so I set action="" in the headers being sent. 首先,我看到soapAction="" ,所以我在发送的标题中设置了action="" This failed. 这失败了。 The correct data that goes into the header is the operation , making it action="getProducts" . 进入标题的正确数据是operation ,使其成为action="getProducts"

Based on the manual for SoapClient and the answer to php using SOAP with a different SoapAction , your request should have worked with: 根据SoapClient的手册和使用不同SoapAction的SOAP的php的答案,您的请求应该使用:

$client = new SoapClient( "http://myWebsite.com/services/MyFirstWebService?wsdl", $options );
$result = $client->__soapCall( "getItemField", array('123456') );

Did you ever omit the $options sent to __soapCall() to simply not specify an action (rather than passing in a blank one)? 你有没有省略发送给__soapCall()$options ,而不是指定一个动作(而不是传递一个空白的动作)?

Its difficult to help without having all the details necessary but I will advise you try the following: 如果没有必要的所有细节,很难提供帮助,但我会建议您尝试以下方法:

//Replace accordingly: see PHP Manual
//(http://www.php.net/manual/en/soapheader.soapheader.php)

$header = new SoapHeader($namespace, $name, $data, $mustunderstand, $actor);
$client->__setSoapHeaders($header);

//Main soap call follows....

before making the call to the soap service. 在拨打肥皂服务之前。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM