[英]PHP and no Soap action header
我正試圖在我的公司內撥打遠程網絡服務。 出於專有原因,我無法提供Web服務的URL。 Web服務有一個名為getItemField的函數。 這是一個小型測試服務,我正在嘗試運行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>
我可以很好地連接到服務並打印出單個函數和類型的名稱,但是當我嘗試調用函數時,我得到'沒有SOAPAction頭!' 錯誤。 我調用服務函數的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 );
根據服務的描述,它似乎沒有定義soapaction。 我用soapAction看到的行是<wsdlsoap:operation soapAction=""/>
。 我試圖指定一個空白的soapAction,因為沒有定義,但這似乎不起作用。 Web服務定義本身是否不完整? 或者我在客戶端應用程序調用中缺少一些參數? 提前致謝。
更新:
試圖將方法名稱指定為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,我該怎么辦,即如果它設置為“”。
我有一個類似的問題,但我使用的是cURL
而不是SoapClient
,盡管解決方案可能是相同的。
向終端服務發送請求時,您必須發送指定Content-Type
的標頭。 在此標題中,您還可以指定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);
在我的情況下,看起來與你的相同,wsdl列出了以下內容:
<wsdl:operation name="getProducts">
<soap:operation soapAction=""/>
<!-- trimmed -->
</wsdl:operation>
首先,我看到soapAction=""
,所以我在發送的標題中設置了action=""
。 這失敗了。 進入標題的正確數據是operation
,使其成為action="getProducts"
。
根據SoapClient
的手冊和使用不同SoapAction的SOAP的php的答案,您的請求應該使用:
$client = new SoapClient( "http://myWebsite.com/services/MyFirstWebService?wsdl", $options );
$result = $client->__soapCall( "getItemField", array('123456') );
你有沒有省略發送給__soapCall()
的$options
,而不是指定一個動作(而不是傳遞一個空白的動作)?
如果沒有必要的所有細節,很難提供幫助,但我會建議您嘗試以下方法:
//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....
在撥打肥皂服務之前。 希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.