2017-05-31 122 views
1

我的php soapclient項目存在問題。 由於現在我用curl發送soap請求,但由於不同的原因,我必須使用PHP的集成soap客戶端。具有多個命名空間的PHP SOAP客戶端

我用於捲曲

我的(工作)的要求是這樣的:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:asc="http://asc.ws.ideal.com" xmlns:xsd="http://getserviceeventstatus.info.asc.ws.ideal.com/xsd"> 
    <soap:Header/> 
    <soap:Body> 
     <asc:getServiceEventStatus>   
     <asc:param>  
      <xsd:info>    
       <xsd:includePreviousEventsInfo>true</xsd:includePreviousEventsInfo>    
       <xsd:mainAscReferenceId>16111294</xsd:mainAscReferenceId>   
      </xsd:info>   
      <xsd:password>xxx</xsd:password>    
      <xsd:userId>xxx</xsd:userId> 
     </asc:param> 
     </asc:getServiceEventStatus> 
    </soap:Body> 
</soap:Envelope> 

我實際的PHP腳本看起來像......

 <?php 
error_reporting(E_ALL); 

$wsdl = '/services/AscServiceSync?wsdl'; 
$location = '/services/AscServiceSync.AscServiceSyncHttpSoap11Endpoint/'; 

$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/', 
'style'=>SOAP_RPC, 
'use'=>SOAP_ENCODED, 
'soap_version'=>SOAP_1_1, 
'cache_wsdl'=>WSDL_CACHE_NONE, 
'connection_timeout'=>15, 
'trace'=>true, 
'encoding'=>'UTF-8', 
'exceptions'=>true, 
"location"=>$location 
); 

$client = new SoapClient($wsdl, $options); 
$result = $client->getServiceEventStatus(array('userId' => 'xxx', 'password' => 'xxx', 'mainAscReferenceId' => '16111294')); 
var_dump ($result); 
print '<br />'; 
print $result->success; 
print '<br />'; 

?> 

服務器返回的錯誤信息,即「參數」或「信息」數據丟失

希望有人能幫助我 謝謝!

+0

您可以使用Fiddler2或其他數據包嗅探器來查看您發送的內容嗎?這會告訴你不同之處。 –

回答

0

一個錯誤可能是你沒有設置includePreviousEventsInfo =>真

一位小提琴手跟蹤會顯示其他任何區別,就像需要做一些地方和mainAscReferenceId的「信息」節點內。對於一些HTTPS站點,Fiddler將提供在中間解碼流量時爲男士安裝假證書。

您也可以將請求發送到任何接受HTTP的其他站點,以查看發送的內容。

0

我將請求發送到我自己的服務器並使用wireshark檢查包。

那是什麼發送到服務器:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://asc.ws.ideal.com"><SOAP-ENV:Body><ns1:getServiceEventStatus/></SOAP-ENV:Body></SOAP-ENV:Envelope> 

我還添加了「includePreviousEventsInfo」的價值,但它不幫助的。 我發現服務器錯誤信息更改爲「信息」丟失時,我把「參數」,而不是「userId」 - 當我更改userId爲「信息」錯誤信息更改爲「參數」丟失...

0

從你的wireshark xml響應看來,soapClient並沒有發送你在你的問題中提到的確切的XML請求。您也可以使用下面的行檢查最後生成的XML並進行調試。

$res = $client->__getLastRequest(); 

您的SOAP服務器需要多個嵌套的XML請求,您可以通過傳遞多維數組來生成該請求。

$reqArr = [ 
    'info' => [ 
     'includePreviousEventsInfo' => true, 
     'mainAscReferenceId' => 16111294 
    ], 
    'password' => 'xxxxxx', 
    'userId' => 'xxxxxx', 
]; 

$res = $client->__soapCall('getServiceEventStatus', $reqArr); 

如果它仍然給你錯誤,那麼從上面的方法檢查最後一個請求XML。

希望它有幫助。