简体   繁体   English

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

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

I want to consume SOAP webservices in php. 我想在php中使用SOAP Web服务。 I got success when wsdl path is over http protocol but when I changed to https this started to throw following exception. wsdl路径通过http协议获得了成功,但是当我更改为https时,这开始引发以下异常。

SOAP-ERROR: Parsing WSDL: Couldn't load from ' https://localhost:8443/../someWsdl.wsdl ' : failed to load external entity " https://localhost:8443/.../someWsdl.wsdl " SOAP错误:解析WSDL:无法从' https:// localhost:8443 /../ someWsdl.wsdl '加载:无法加载外部实体“ https:// localhost:8443 /.../ someWsdl.wsdl

This exception is thrown at a time of SOAPClient object creation. 在创建SOAPClient对象时抛出此异常。 I compared both the wsdl files obtained by http and https, both have same content except webservice location path in one place. 我比较了通过http和https获得的wsdl文件,它们的内容都相同,除了webservice位置路径在一个地方。 So why parsing exception is thrown? 那么为什么会抛出异常解析呢?

I have tried some of the suggestions from Internet but that don't work for me: 我尝试了Internet上的一些建议,但对我不起作用:

  1. Enable soap, openssl in php. 在php中启用soap,openssl。
  2. Passing local_cert as option with local certificate path in the constructor of SoapClient call. 在SoapClient调用的构造函数中将local_cert作为选项与本地证书路径一起传递。
  3. Passing wsdl location as https://oc_username:oc_password@localhost:8443/OpenClinica-ws/ws/study/v1/studyWsdl.wsdl for login into openclinica and then access webservice. 将wsdl位置作为https:// oc_username:oc_password @ localhost:8443 / OpenClinica-ws / ws / study / v1 / studyWsdl.wsdl传递以登录到openclinica,然后访问Web服务。

My requirement is to access webservices over https protocol. 我的要求是通过https协议访问Web服务。 Is there any other options which need to pass in SoapClient constructor for creating SoapClient object, when web-service URL path is over https protocol? 当Web服务URL路径通过https协议时,是否还有其他需要传递给SoapClient构造函数来创建SoapClient对象的选项? Can you please help me to resolve above issue and suggest any reference document available for it. 您能否帮助我解决以上问题,并提出任何可用的参考文件。

Updated: This is my code: 更新:这是我的代码:

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

I had a similar issue that was caused by the XML in the WSDL file specifying port 81 while attempting to use HTTPS (should be 443). 我有一个类似的问题,该问题是由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>

I fixed this by specifying the location option of the PHP SoapClient to that of my WSDL file. 我通过将PHP SoapClient的location选项指定为WSDL文件的location选项来解决此问题。 This explicitly forced the location to the HTTPS address. 这明确地将位置强制为HTTPS地址。 Snippet: 片段:

$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);

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

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