2012-04-25 143 views
2

我正在嘗試使用以下PHP代碼建立SOAP連接,並且它在SoapClient構造點失敗:SoapClient LibXMLError:無法加載外部實體,SOAP-ERROR:解析WSDL:無法加載

// Need to declare these settings here because our php.ini has alternate 
// settings due to global purposes for other PHP scripts 
ini_set("soap.wsdl_cache_enabled", "0"); 
ini_set("soap.wsdl_cache", "0"); 
ini_set("display_errors","On"); 
ini_set("track_errors","On"); 

// FedEx web services URL, note the HTTPS 
$path_to_wsdl = 'https://wsbeta.fedex.com/web-services'; 

$soap_args = array(
    'exceptions'=>true, 
    'cache_wsdl'=>WSDL_CACHE_NONE, 
    'trace'=>1) 
; 

try { 
    $client = new SoapClient($path_to_wsdl,$soap_args); 
} catch (SoapFault $e) { 
    var_dump(libxml_get_last_error()); 
    echo "<BR><BR>"; 
    var_dump($e); 
} 

此輸出:

object(LibXMLError)#1 (6) { 
    ["level"]=> int(1) 
    ["code"]=> int(1549) 
    ["column"]=> int(0) 
    ["message"]=> string(71) "failed to load external entity "https://wsbeta.fedex.com/web-services" " 
    ["file"]=> string(0) "" 
    ["line"]=> int(0) 
} 

object(SoapFault)#2 (9) { 
    ["message":protected]=> string(158) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://wsbeta.fedex.com/web-services' : failed to load external entity "https://wsbeta.fedex.com/web-services" " 
    ["string":"Exception":private]=> string(0) "" 
    ["code":protected]=> int(0) 
    ["file":protected]=> string(53) "/mnt/array/bell-enterprise/bell/fedex_shipservice.php" 
    ["line":protected]=> int(34) 
    ["trace":"Exception":private]=> array(1) { 
     [0]=> array(6) { 
      ["file"]=> string(53) "/mnt/array/bell-enterprise/bell/fedex_shipservice.php" 
      ["line"]=> int(34) 
      ["function"]=> string(10) "SoapClient" 
      ["class"]=> string(10) "SoapClient" 
      ["type"]=> string(2) "->" 
      ["args"]=> array(2) { 
       [0]=> string(37) "https://wsbeta.fedex.com/web-services" 
       [1]=> array(4) { 
        ["exceptions"]=> bool(true) 
        ["soap_version"]=> int(1) 
        ["cache_wsdl"]=> int(0) 
        ["trace"]=> int(1) 
       } 
      } 
     } 
    } 
    ["previous":"Exception":private]=> NULL 
    ["faultstring"]=> string(158) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://wsbeta.fedex.com/web-services' : failed to load external entity "https://wsbeta.fedex.com/web-services" " 
    ["faultcode"]=> string(4) "WSDL" 
} 

回答

8

經過6個小時的頭痛之後,唯一的解決方案是下載WSDL文件。

https://wsbeta.fedex.com/web-serviceshttps://ws.fedex.com/web-services

它總是拋出一個錯誤500,因爲這不是WSDL。

一旦從技術資源下載的WSDL - >聯邦快遞的WebServices航運 - > GetStarted(點擊「速度服務」,然後選擇「下載WSDL或XML」),在你的腳本,你需要加載您的本地存儲的WSDL,一切都將像魅力一樣工作。

$this->_soapClient = new SoapClient("RateService_v13.wsdl", array('exceptions'=>true, 'trace' => true)); 

玩得開心!

+0

謝謝賈斯汀。這是我最終發現自己是真實的,當我回過頭來看這篇文章時,我從來沒有把正確的答案關掉。你的確是正確的解決方案,我幾小時後在牆上敲打我的頭也找到了正確的解決方案。聯邦快遞的文件在這方面極其缺乏。 – David 2013-10-03 20:27:38

0

你需要一個本地證書文件來訪問HTTPS一個WSDL:

$client = new SoapClient($wsdl, array('local_cert' => $pathToLocalCert)); 

將此選項追加到您當前的$soap_args,此代碼應按預期工作。如果您需要證書,則還可以使用passphrase選項。

+0

我已經這麼做了,我刪除了該選項,因爲它沒有什麼區別。該證書對輸出沒有任何影響。 – David 2012-04-25 15:33:20

+0

在php.ini設置中是否啓用'allow_url_fopen'? – alganet 2012-04-25 16:34:24

+0

是的,allow_url_fopen已啓用 – David 2012-04-25 17:30:11

2

該url不是WSDL的路徑,而是SOAP請求應該到達的URL。從來沒有與這些傢伙合作,但我收集你可以得到一個wsdl文件並將其存儲在本地,並且您可以將該wsdl中的端點更改爲wsbeta。我無法找到wsdl,而且fedex網站也不允許我在沒有註冊的情況下進一步開發他們的開發技術資源,所以我會留下它:wsdl是其他地方,您擁有的網址只是特定服務的位置。

+0

謝謝Wrikken。正如賈斯廷的回答中所指出的那樣,我檢查了他,因爲它與我的問題相關的更精確和完整,但你的回答也是正確的。 – David 2013-10-10 18:26:08

相關問題