当使用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 没有以正确的方式解析与 WSDL 的链接,使其能够正确链接到 .xsd 文件。
令人沮丧的是,客户端输出的 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());
};