SoapClient LibXMLError:无法加载外部实体,SOAP-ERROR:解析WSDL:无法加载

时间:2012-04-25 15:10:55

标签: php xml web-services soap wsdl

我正在尝试使用以下PHP代码建立SOAP连接,并且它在SoapClient构造时失败了:

// 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"
}

3 个答案:

答案 0 :(得分:8)

经过6个小时的头痛,唯一的解决方案是下载WSDL文件。

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

它总是会抛出错误500,因为这不是wsdl。

技术资源 - &gt;下载wsdls后FedEx WebServices For Shipping - &gt; GetStarted (单击“评价服务”,然后“下载WSDL或XML”),在您的脚本中,您将需要加载本地存储的WSDL,一切都将像魅力一样。

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

玩得开心!

答案 1 :(得分:2)

该url不是WSDL的路径,而是SOAP请求应该去的URL。从来没有和这些人一起工作过,但是我知道你可以在某个地方获得一个wsdl文件并将其存储在本地,你可以将wsdl中的端点改为wsbeta。我找不到wsdl和联邦快递网站不允许我在没有注册的情况下进一步使用他们的开发技术资源,所以我会留下它:你 wsdl 在别的地方,网址你拥有的只是特定服务的位置。

答案 2 :(得分:0)

您需要一个本地证书文件来访问HTTPS上的WSDL:

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

将此选项附加到当前$soap_args,此代码应按预期工作。如果您需要证书,也可以使用passphrase选项。