尝试使用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文件的longform版本。将其替换为WSDL文件可以解决这个问题,但是服务的其余部分会崩溃。我的主要障碍似乎是SoapClient没有以可能正确链接到.xsd文件的方式解析到WSDL的链接。
令人沮丧的是,客户端输出的XML已被证明是有效的;我已经将生成的XML复制到SoapUI中,并在shortform 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());
};
答案 0 :(得分:0)
您可能需要查看WSSE标头身份验证 - 才能通过SSL登录。
有关示例(请参阅Connecting to WS-Security protected Web Service with PHP)
,请参阅https://stackoverflow.com/a/6677930/354709