简体   繁体   English

Soapclient没有解析WSDL(使用SSL证书和wsse)

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

When trying to implement a web service with SoapClient it appears that the wsdl link isn't being resolved; 尝试使用SoapClient实现Web服务时,似乎没有解析wsdl链接; when attempting to create a new SoapClient object, the request fails with the message: 尝试创建新的SoapClient对象时,请求失败并显示以下消息:

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

The WSDL contains relative links to the .xsd files for the request and response, however when the client attempts to load them they do not exist. WSDL包含指向请求和响应的.xsd文件的相对链接,但是当客户端尝试加载它们时,它们不存在。 When navigating to the WSDL file in the browser, it redirects to the longform version of the .wsdl file. 在浏览器中导航到WSDL文件时,它会重定向到.wsdl文件的longform版本。 Substituting this into the WSDL file works for getting around this however the rest of the service falls apart. 将其替换为WSDL文件可以解决这个问题,但是服务的其余部分会崩溃。 My main obstacle seems to be that SoapClient isn't resolving the link to the WSDL in a way that it may correctly link to the .xsd files. 我的主要障碍似乎是SoapClient没有以可能正确链接到.xsd文件的方式解析到WSDL的链接。

Frustratingly, the XML being output by the client has been proven to be valid; 令人沮丧的是,客户端输出的XML已被证明是有效的; I've copypasted the generated XML into SoapUI and fired it at the shortform WSDL and it has returned the expected result. 我已经将生成的XML复制到SoapUI中并将其解析为shortform WSDL并返回了预期的结果。

Below is the code for the SoapClient. 下面是SoapClient的代码。 Any ideas? 有任何想法吗?

<?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());
};

You may need to look at WSSE Header Authentication - to get past the SSL login. 您可能需要查看WSSE标头身份验证 - 才能通过SSL登录。

See Connecting to WS-Security protected Web Service with PHP for some examples (especially https://stackoverflow.com/a/6677930/354709 ) 有关示例,请参阅使用PHP连接到受WS-Security保护的Web服务 (特别是https://stackoverflow.com/a/6677930/354709

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM