在 https 协议上访问 SOAP Web 服务会引发异常 SOAP-ERROR:解析 WSDL


Accessing SOAP webservices on https protocol throws Exception SOAP-ERROR: Parsing WSDL

我想在php中使用SOAP Web服务。当 wsdl 路径通过 http 协议时,我取得了成功,但是当我更改为 https 时,这开始引发以下异常。

SOAP-ERROR: 解析 WSDL: 无法从"https://localhost:8443/../someWsdl.wsdl"加载: 无法加载外部实体 "https://localhost:8443/.../someWsdl.wsdl"

此异常在创建 SOAPClient 对象时引发。我比较了通过http和https获得的两个wsdl文件,除了Web服务位置路径在一个地方之外,它们都具有相同的内容。那么为什么要抛出解析异常呢?

我已经尝试了一些来自互联网的建议,但对我不起作用:

  1. 启用 soap,在 php 中打开。
  2. 在 SoapClient 调用的构造函数中使用本地证书路径传递local_cert作为选项。
  3. 将 wsdl 位置作为登录 openclinica 然后访问 Web 服务的 https://oc_username:oc_password@localhost:8443/OpenClinica-ws/ws/study/v1/studyWsdl.wsdl 传递。

我的要求是通过https协议访问Web服务。当Web服务URL路径通过https协议时,是否有任何其他选项需要传入SoapClient构造函数来创建SoapClient对象?您能否帮助我解决上述问题并建议任何可用的参考文档。

更新:这是我的代码:

$wsdl = "https://localhost:8443/.../someWsdl.wsdl"; $client = new SoapClient($wsdl, array( 'trace' => 1 ));

我遇到了类似的问题,这是由 WSDL 文件中的 XML 在尝试使用 HTTPS(应该是 443)时指定端口 81 引起的。

<wsdl:service name="API">
    <wsdl:port name="APISoap" binding="tns:APISoap">
        <soap:address location="http://example.com:81/api.asmx"/>
    </wsdl:port>
    <wsdl:port name="APISoap12" binding="tns:APISoap12">
        <soap12:address location="http://example.com:81/api.asmx"/>
    </wsdl:port>
</wsdl:service>

我通过将 PHP SoapClient 的location选项指定到我的 WSDL 文件的选项来解决此问题。这会显式地将该位置强制为 HTTPS 地址。片段:

$wsdl = "https://example.com/api.asmx?wsdl";
$SSL['verify_peer_name'] = true;        // Verify the peer name from the WSDL hostname
$SSL['verify_peer']      = true;        // Verify SSL connection to host
$SSL['disable_compression'] = true;     // Helps mitigate the CRIME attack vector
$context['ssl'] = $SSL;
$options['location'] = $wsdl;      // Force the endpoint to be HTTPS (WSDL returns endpoint as HTTP at Port 81)
$options['stream_context'] = stream_context_create($context);
$client = new SoapClient($wsdl, $options);