This is a beginner tutorial to help beginners make a call to “wsdl” files and for them to display the results returned by the service.

First step is to include “nusoap.php” in \vendors folder in cakephp setup. In the controller, we make a call to nusoap.php by the statement App::import(‘Vendor’,’nusoap’);

Controller: /app/controllers/primenumbers_controller.php

<?php
App::import('Vendor','nusoap');
class PrimenumbersController extends AppController{
	var $uses = array();
	var $name = "Primenumbers";
	
	function index(){
		// Initialize variables
		$data    = array();
		$message = array();
		$client  = new nusoap_client('http://www50.brinkster.com/vbfacileinpt/np.asmx?wsdl', 'wsdl');
		
		if(empty($this->params['pass'])){
		// Set the parameters
		$param = array('max' => '100');
		}else{			
		// Set the parameters after validating the parameters
		$param = array('max' => $this->params['pass'][0]);	
		}
		$result = $client->call('GetPrimeNumbers', array('parameters' =>$param), '', '', false, true);

		// Set the faulty message
		if ($client->fault) {
			$this->set('message', $result);
		} else {
			// Set the error
			$err = $client->getError();
			if ($err) {
				$this->set('message', $err);
			} else {
			// Set the result
				$this->set('data', $result);
			}
		}
	}
}
?>

Now, create a view to display the results from the web service call.

View: /app/views/primenumbers/index.ctp

<?php
if(!empty($data)){
	echo "List of prime numbers = ".$data['GetPrimeNumbersResult'];
}else{
	echo "<pre>";
	pr($message);
	echo "</pre>";
}
?>

The above view will display all prime numbers less than the parameter passed to the controller. If no parameters are passed, prime numbers less than 100 gets displayed. The above is just an example using a web service listed from brinkster to set the beginner in the right track.