13/12/14 php , webservices # , , , , , , ,

PHP SoapClient with cURL powered request

I stumbled upon a SOAP related problem at work recently; I needed to consume a SOAP web service secured by two way authentication via self signed SSL certificates (…). This service was provided by another department so there was no arguing whether to use SOAP or, my personal preference, REST.

My project is build out of two components; An AngularJS front-end webapp and a CakePHP powered REST API. The CakePHP API created one endpoint for the front-end clients and connected them to all sorts of different data-sources (MongoDB, local MySQL, remote MySQL and a SOAP service).

So, back to the problem (and solution) at hand; For SOAP I started using PHP’s native SoapClient class. This works pretty nice if you have the WSDL and XSD files for the service, it even should work with SSL certificates, private keys and passphrases… except it doesn’t… For some reason (PHP 5.3, don’t ask…) the requirement of the service to pass both a client certificate as well as a private key with passphrase doesn’t work (failed to enable crypto error).

After some searching I kept finding a workaround using cURL to make the SOAP request so I went with that and could indeed make the SOAP call. The result unfortunately was, of course, raw XML I had to parse manually to get my data. Apart from that I also had to create the SOAP envelope and request body myself by just creating a string instead of using the data param in the SoapClient way.

Ok, enough problems and inconveniences lets get to the solutions!

I extended the SoapClient class and overwrote the __doRequest method with a cURL powered method body, returning the raw XML of the result afterwards lets the SoapClient class parse it and validate it against the XSD, this way you have the best of both worlds; The power and ease of the SoapClient class and the flexibility of cURL for the actual request.

The code is posted on GitHub as a gist including an example:



0 likes 5 responses
Hi there!
12/12/14 Uncategorized

Hi there!

Hi there! Wow.. this is my first real blog post on the new version of my website. I recently decided to start posting what I come across in my work and hobby regarding everything webdevelopment related. More stuff coming soon, going to post some experiences I had in the near past.

0 likes no responses