2011-11-22 84 views
5

我想在我的公司内调用远程Web服务。出于专有原因,我无法提供网络服务的URL。该Web服务具有一个称为getItemField的单个函数。这是我想针对其运行PHP一个小的测试服务,该服务的描述如下: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> 

我可以连接到服务就好了,并打印出单功能和类型的名称,但是当我尝试调用一个函数时,我得到'no SOAPAction header!'错误。我的PHP代码来调用服务功能如下:基于有一个定义的SOAPAction它不会出现在服务的描述

$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); 

。我用soapAction看到的这条线是<wsdlsoap:operation soapAction=""/>。我试图指定一个空白的soapAction,因为没有定义,但似乎没有工作。 Web服务定义本身是否不完整?或者我在客户端应用程序调用中缺少一些参数?提前致谢。

UPDATE:

试图以指定的方法名作为SOAP动作,但htat没有工作。

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

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

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

那我如果WSDL,即没有指定的soapAction做,如果它被设置为“”。

+0

对此有何更新?当我尝试通过curl连接到可以通过Zend soap连接的web服务时,我遇到了同样的问题,所以我想它与一些选项或标头相关。 –

+0

不是与HTTP标头相关的SOAPAction标头吗?检查http://www.oreillynet.com/xml/blog/2002/11/unraveling_the_mystery_of_soap.html – pedromanoel

回答

-1

它很难帮助,而不必所有的细节必要的,但我会建议您尝试以下方法:

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

使得调用SOAP服务之前。 希望这有助于。

+0

为什么downvote?它对@profnotime和所有来这里寻找答案的人都是非常粗鲁的...... – pedromanoel

+0

SoapHeader用于填充SOAP请求的部分。它不设置HTTP标头。 – Andrew

2

我有类似的问题,但我使用cURL而不是SoapClient,虽然解决方案可能是相同的。

向终端服务发送请求时,必须发送指定Content-Type的标头。在这个标题中,您也可以指定action或“肥皂行动”。

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

在我的情况,并似乎是一样的你,在WSDL列出了以下内容:

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

起初,我看到soapAction="",所以我设置的头action=""发送。这失败了。进入标题的正确数据是operation,使其成为action="getProducts"

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

你有没有忽略发送到__soapCall()根本就没有指定动作$options(而不是通过在:

基于手册SoapClient和答案php using SOAP with a different SoapAction上,你的要求应该有工作一个空白的)?