gpt4 book ai didi

php - Soapclient 不解析 WSDL(使用 SSL 证书和 wsse)

转载 作者:数据小太阳 更新时间:2023-10-29 02:45:07 25 4
gpt4 key购买 nike

当尝试使用 SoapClient 实现 Web 服务时,似乎没有解析 wsdl 链接;尝试创建新的 SoapClient 对象时,请求失败并显示消息:

Request failed. Reason: SOAP-ERROR: Parsing Schema: can't import schema from 'https://dev.example.com/StubService/RequestService.xsd'

WSDL 包含指向请求和响应的 .xsd 文件的相关链接,但是当客户端尝试加载它们时,它们并不存在。在浏览器中导航到 WSDL 文件时,它会重定向到 .wsdl 文件的长格式版本。将其替换到 WSDL 文件中可以解决这个问题,但服务的其余部分会崩溃。我的主要障碍似乎是 SoapClient 没有以可以正确链接到 .xsd 文件的方式解析到 WSDL 的链接。

令人沮丧的是,客户端输出的 XML 已被证明是有效的;我已将生成的 XML 复制粘贴到 SoapUI 中并在短格式 WSDL 中触发它,它返回了预期的结果。

下面是 SoapClient 的代码。有什么想法吗?

<?php
// The shorthand wsdl that should be used
// The long wsdl it should resolve to is https://dev.example.com/StubService/WebService/WEB-INF/wsdl/SearchByPropertyDescriptionV2_0Service.wsdl
$wsdl = 'https://dev.example.com/StubService/WebService?wsdl';

try
{
// Create a new soap client
$client = new SoapClient($wsdl,
array(
'local_cert' => MY_KEY,
'passphrase' => MY_PASSWORD,
'locale' => 'en',
'trace' => true,
'exceptions' => true,
));

//set the Headers of Soap Client.
$username = 'User001';
$password = 'Pass001';

$security = 'MY_SECURITY_HEADER';
$securityheader = new \SoapVar($security,XSD_ANYXML, null, null, null);

$international = 'MY_INTERNATIONAL_HEADER';
$internationalheader = new \SoapVar($international,XSD_ANYXML, null, null, null);

$headers = array(
new SoapHeader('null', 'wsse', $securityheader),
new SoapHeader('null', 'i18n', $internationalheader)
);

$client->__setSoapHeaders($headers);

// Create the XML body
$params = new SoapVar('MY_VALID_XML_BODY', XSD_ANYXML);

$result = $client->searchProperties($params));
var_dump($result);
}
catch (Exception $e)
{
echo "Request failed. Reason: ".$e->getMessage();
echo "<br />";
echo "Last request:\n";

var_dump($client->__getLastRequest());
};

最佳答案

您可能需要查看 WSSE header 身份验证 - 以通过 SSL 登录。

参见 Connecting to WS-Security protected Web Service with PHP对于一些例子(特别是 https://stackoverflow.com/a/6677930/354709 )

关于php - Soapclient 不解析 WSDL(使用 SSL 证书和 wsse),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24910663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com