2017-09-04 214 views
8

使用PHP SoapClient的,我做的WSDL調用在https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl和我得到以下XML響應(通過$soapclient->__last_response所示)PHP SoapClient的返回null,甚至認爲有一個響應

<?xml version='1.0' encoding='UTF-8'?><soap:Envelope xmlns:ede="http://ede.de/webservices" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><Response action="ELC" requestId="1" version="1.0"><created>2017-09-04T16:04:46.556+02:00</created><StatusInformation>OK</StatusInformation><StatusCode>0</StatusCode><Payload><SalesOrderSimulateConfirmation><Items><Item><ID>10</ID><ProductID>0003062700050</ProductID><Price>2.970</Price><PositionPrice>2.970</PositionPrice><PriceUnit>1</PriceUnit><QuantityUnit>ST</QuantityUnit><QuantityAvailable>1</QuantityAvailable><QuantityProfile>1</QuantityProfile><Currency>EUR</Currency><Services /><Schedules>Geplante Liefertermine: 1 ST in KW 36.2017;</Schedules><Remark /><DangerMaterial /></Item></Items></SalesOrderSimulateConfirmation></Payload></Response></soap:Body></soap:Envelope> 

儘管如此,來電$soapclient->simulateOrder()回報null

如何讓PHP SoapClient的返回一個對象,而不是空的?

注:我使用的肥皂調用XML手動生成由一個覆蓋到SoapClient::__doRequest()。爲SOAP調用的代碼如下所示:

$soapClient = new SoapClient('https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl', array(
    'cache_wsdl' => WSDL_CACHE_NONE, 
    'trace'  => true, 
    'exceptions' => true, 
    'soap_version' => SOAP_1_2, 
    'features'  => SOAP_SINGLE_ELEMENT_ARRAYS, 
    'login' => '------', // cannot post here for security purposes 
    'password' => '-----', // cannot post here for security purposes 
    'stream_context' => (
     stream_context_create(array(
      'ssl' => array(
       'verify_peer' => false, 
       'verify_peer_name' => false, 
       'allow_self_signed' => true 
      ) 
     )) 
)); 
$result = $soapClient->simulateOrder(); 

沒有異常拋出,但$resultnull

+0

你能告訴我們你的函數simulateOrder()嗎? –

回答

3

的問題是SSL設置,當我嘗試打電話給您的代碼所引發的錯誤我服務器如下:

致命錯誤:未捕獲的SOAPFault異常:[WSDL] SOAP的錯誤:解析WSDL:無法從 'https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl' 中加載:未能加載外部實體 「https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl」 在/ home/repojarilo /的public_html /sc.php:22堆棧跟蹤:#0 /home/repojarilo/public_html/sc.php(22):所以, apClient-> SoapClient('https://webserv ...',Array)#1 {main}拋出...在第22行

我假設您試圖讓代碼與自簽名證書一起工作在請求中的SSL數組中,但它看起來像SoapClient沒有注意到它並拋出錯誤。

所以我的解決方案是要麼購買SSL(非常便宜的日子,嘗試諸如namecheap等網站...)或使用類似https://letsencrypt.org/的東西來獲得一個SSL,這將允許您的肥皂客戶端正常工作。

最後,我注意到一個錯字,在你的代碼前一行你有));應該是)));

Koda

1

問題不是您的證書作爲客戶端,而是服務器證書本身(嘗試在瀏覽器中加載https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl),這是無效的。你可以完全忽略它,作爲服務器證書,它主要是爲了避免網絡釣魚,並且我明白,它是你真正想要達到的網址。在命令行curl中,這是通過-k選項實現的。在PHP中,SoapClient完全可以使用this(完全是你的問題,檢查第三個答案,並查看關於PHP7的說明)。

注意:您正在每次構建SoapClient時加載服務的定義文件wsdl。如果將$ soapclient作爲靜態變量存儲,則可以始終使用它的方法,而無需重新創建客戶端對象(因此,避免重新加載並重新解釋wsdl文件,該文件可能會在1到5秒內完全延遲),所有時間。

相關問題