SOAP Client In CodeIgniter using NuSOAP PHP Toolkit
To create SOAP client in CodeIgniter, it is better to use NuSOAP (SOAP Toolkit for PHP).
Download NuSOAP Toolkit from this URL: Download
Below are the steps to create SOAP client in CodeIgniter using NuSOAP PHP Toolkit.
Step 1: After downloading NuSOAP toolkit, copy “lib” and “nusoap” folder in “application/library/” folder.
Step 2: Create one library file say “nusoap_library.php” in “application/library” folder and copy and paste below given code in “application/library/nusoap_library.php” file. It just includes “nusoap.php” library file from “lib” folder.
class Nusoap_library { function Nusoap_library() { require_once('lib/nusoap'.EXT); } }
Step 3: SOAP request function. Copy and paste below given function to “application/library/nusoap_library.php” file.
function soaprequest($api_url, $api_username, $api_password, $service, $params) { if ($api_url != '' && $service != '' && count($params) > 0) { $wsdl = $api_url."?wsdl"; $client = new nusoap_client($wsdl, 'wsdl'); $client->setCredentials($api_username,$api_password); $error = $client->getError(); if ($error) { echo "\nSOAP Error\n".$error."\n"; return false; } else { $result = $client->call($service, $params); if ($client->fault) { print_r($result); return false; } else { $result_arr = json_decode($result, true); $return_array = $result_arr['result']; return $return_array; } } } }
Step 4: To send SOAP request to SOAP web service method, we need to load NuSOAP library in Controller where we want to use SOAP client.
$this->load->library("Nusoap_lib", "");
Step 5: SOAP service call in Controller
$api_url = WEBSERVICE_URL; // ex. http://www.example.com/index.php/soapserver $api_username = AUTHENTICATION USERNAME; $api_password = AUTHENTICATION PASSWORD; $service = "addnumbers"; // from my POST <a href="http://www.php-guru.in/2013/soap-server-in-codeigniter-using-nusoap-library/" target="_blank">SOAP Server In CodeIgniter using NuSOAP PHP Toolkit</a> $params = array('a' => 5, 'b' => 10); // input parameters to "addnumbers" medhod if ($api_url != '') { $result = $this->nusoap_lib->soaprequest($api_url, $api_username, $api_password, trim($service), $params); if (is_array($result) && count($result) > 0) { print_r($result); } }
Hope this post will help you !!!
Comments are currently closed.