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


Soapclient isn't resolving WSDL (with SSL certificate and wsse)

当尝试使用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 Authentication -以通过SSL登录。

请参阅使用PHP连接到受WS-Security保护的Web服务的一些示例(特别是https://stackoverflow.com/a/6677930/354709)