How To: PHP SOAP client in WSDL mode over SSL (private key) with HTTP authentication

by Niki on November 10, 2011

Whoa, what a title. Don’t be discouraged though, this post is here to make it (look) easy.

The first thing to know is how to construct a SOAP client in PHP.

Since PHP5 SOAP is baked in natively so this should be fairly easy right? Right.

$client = new SoapClient($wsdl, $soapclient_options);

The SoapClient constructor needs 2 arguments for our example to work. A string variable containing the URL of our webservice’s  WSDL and an array with all of our SOAP options.

The WSDL url:

$wsdl = '' ;

The SOAP options:

$soapclient_options = array();
$soapclient_options['login'] = 'your_http_login';
$soapclient_options['password'] = 'your_http_password';
$soapclient_options['local_cert'] = '/path/to/the/certificate/cert.pem';

There, done, finished, ready to go ! Nope, Chuck Testa! I mean Nope, not yet.

The SOAP client will not use the http login and password options for the WSDL retrieval, it only uses these for the transmission of SOAP messages. We need to change the $wsdl variable so that it contains proper HTTP auth credentials.

$wsdl = 'https://' . $soapclient_options['login'] . ':' . $soapclient_options['password'] . '' ;

There, looking good like this. Now let’s test this thing!

try {
  $our_return_string = $client->DoSomething(); //returns a string
echo $our_return_string;
} catch (SoapFault $exception) {
echo $exception;

This is how easy it is to use a PHP SOAP client in WSDL mode over SSL with a private key :)

{ 1 comment… read it below or add one }

HeinrichMS December 6, 2013 at 4:46 pm

Hallo there,

nice things you wrote. Could I ask you for your opinion?

Im using php 5.3, xampp, and wsdl pointing to, and those don’t help. The cert.pem is self-generated. But Im not understanding also why would…wsdl need mine self-generated .pem ?!? In general, I don’t understand how the whole php-soap-https is working, and google doesn’t know much about either … Any answer will be appreciated.


Leave a Comment

Previous post:

Next post: