Nitin
Nitin

Reputation: 43

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

I want to consume SOAP webservices in php. I got success when wsdl path is over http protocol but when I changed to https this started to throw following exception.

SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://localhost:8443/../someWsdl.wsdl' : failed to load external entity "https://localhost:8443/.../someWsdl.wsdl"

This exception is thrown at a time of SOAPClient object creation. I compared both the wsdl files obtained by http and https, both have same content except webservice location path in one place. So why parsing exception is thrown?

I have tried some of the suggestions from Internet but that don't work for me:

  1. Enable soap, openssl in php.
  2. Passing local_cert as option with local certificate path in the constructor of SoapClient call.
  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.

My requirement is to access webservices over https protocol. 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? 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 ));

Upvotes: 1

Views: 2928

Answers (1)

mjohns
mjohns

Reputation: 369

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: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. This explicitly forced the location to the HTTPS address. 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);

Upvotes: 1

Related Questions