How to consume WSDL in PHP using NuSOAP

I recently got a requirement from a client for a facility to display products/categories prices in real time on his website. The client’s website was related to home interiors, blinds and curtains and as he was short on staff he wanted the website to fetch the products, images and prices without any human interference.

He signed up with a major blinds and curtains supplier in the UK to use their API on his website. The API provided information on products, product prices, product images and additional images etc. I had consumed WSDLs in ASP.NET countless times but this was the first time in PHP.

As expected it was not going to be a problem in PHP as well. NuSOAP is an open source package which allows us to consume WSDL online. I downloaded the package from SourceForge and went about my work. After unzipping the package I found that there are 2 folders within it the Lib folder and the Samples folder.

After going through a couple of files in the Samples folder I coded a script which would fetch all the active products in a category. I have not listed sample request data on purpose as it is confidential. I believe the following code would be enough for anyone who has just started.

<?php

// URL is the WSDL url where the request would be sent and received from
// $params is the array which would pass the request parameters to the URL
// SomeMethod is the name of the method where the parameters woule be passed

require_once('lib/nusoap.php');
$client = new soapclient(URL);
$params = array();  
$result = $client->SomeMethod($params);
print_r($result);

?>

Hope the above helped.

Tagged with: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*