2011-11-22 81 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上,你的要求應該有工作一個空白的)?