【问题标题】:SoapClient LibXMLError: failed to load external entity, SOAP-ERROR: Parsing WSDL: Couldn't loadSoapClient LibXMLError:加载外部实体失败,SOAP-ERROR:解析 WSDL:无法加载
【发布时间】:2012-05-06 07:21:30
【问题描述】:

我正在尝试使用以下 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"
}

【问题讨论】:

    标签: php xml web-services soap wsdl


    【解决方案1】:

    您需要一个本地证书文件才能通过 HTTPS 访问 WSDL:

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

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

    【讨论】:

    • 我已经这样做了,我删除了该选项,因为它没有任何区别。证书对输出没有任何影响。
    • allow_url_fopen 是否在 php.ini 设置中启用?
    • 是的,allow_url_fopen 已启用
    • alganet,顺便说一句 - 我已经看到关于“local_cert”的相互矛盾的答案:它应该是文件的路径,还是提供包含以下内容的字符串的“file_get_contents($path)”证书? (两者都没有为我工作,但无论如何我都会感谢您的反馈,以供我将来参考。)
    【解决方案2】:

    那个 url 不是 WSDL 的路径,而是 SOAP 请求应该去的 url。从未与这些人合作过,但我认为您可以在某处获取一个 wsdl 文件并将其存储在本地,并且您可以将该 wsdl 中的端点更改为 wsbeta 端点。我找不到 wsdl,fedex 网站不允许我在没有注册的情况下进一步了解他们的开发技术资源,所以我将保留它:你 wsdl 在其他地方,网址您拥有的只是特定服务的位置。

    【讨论】:

    • 感谢 Wrikken。正如贾斯汀的回答所指出的,我检查了他的,因为它与我的问题有关,更准确和完整,但你的回答也是正确的。
    【解决方案3】:

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

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

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

    一旦您从技术资源 -> FedEx WebServices For Shipping -> GetStarted 下载 wsdls(点击“Rate Services”,然后点击“Download WSDL or XML”),您将需要在脚本中加载本地存储的 WSDL,一切都会像魅力一样工作。

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

    玩得开心!

    【讨论】:

    • 谢谢贾斯汀。这就是我自己最终发现的真实情况,当我回读这篇原始帖子时,我从未以正确的答案结束它。你的确实是正确的解决方案,我也发现了几个小时的头撞墙。 FedEx 文档在这方面非常缺乏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多