Using php’s new SoapClient, it is really easy to access SOAP based webservices.
It only gets a little bit more complicated if your service is only accessible over ssl. Normally the first error you will see is: Client Authentication Error or Could not connect to host.
In this case you must use a valid certificate to access the service. The format of the certificate must be PEM.
Commonly you get your certificate file as a PKCS12 container (.p12 extension). To use this certifacte with php soap, you have to extract the pem information. This can easily be achieved using the openssl commandline tool (available on almost any linux and osx installation):
openssl pkcs12 -in mycert.p12 -out mycert.pem -nodes -clcerts
Copy this certificate to your soap client path and init your soap client like in this example:
$my_client = new SoapClient('http://myserver.com/myservice.wsdl', array('local_cert' => dirname(__FILE__) . '/mycert.pem'));
That’s it. Now your SOAP Requests over SSL should work as expected.



Comments