Its Very Easy to Create Soap Server on Codeignitor
Step 1.
Download NuSOAP Library from sourceforge Download
Step 2 :
Extract Downloaded zip and Copy lib folder in “application/library”
Now Create nusoap_lib.php in “application/library” and below code in that file
<?php
class Nusoap_lib
{
function Nusoap_lib()
{
require_once(‘lib/nusoap.php’);
}
}
Step 3.
Create soap_server.php in “application/controllers/” and add below code in “application/controllers/soap_server.php”
<?php
class Soap_server extends CI_controller {
function __construct() {
parent::__construct();
$this->load->library(“Nusoap_lib”);
$this->nusoap_server = new soap_server();
$this->nusoap_server->configureWSDL(“Bills_WSDL”, “urn:Soap_server”);
$this->nusoap_server->register(‘hello’, // method name
array(‘name’ => ‘xsd:string’), // input parameters
array(‘return’ => ‘xsd:string’), // output parameters
‘urn:Soap_server’, // namespace
‘urn:Soap_server#hello’, // soapaction
‘rpc’, // style
‘encoded’, // use
‘Says hello to the caller’ // documentation
);
}
function index(){
if($this->uri->rsegment(3) == “wsdl”) {
$_SERVER[‘QUERY_STRING’] = “wsdl”;
} else {
$_SERVER[‘QUERY_STRING’] = “”;
}
function hello($name) {
return ‘Hello, ‘ . $name;
}
$this->nusoap_server->service(file_get_contents(“php://input”));
}
}
Step 4:
Make this Entry in /config/routes.php
$route[‘soap_server/wsdl’] = “Bills_WS/index/wsdl”;
Try to access WSDL Now
http://localhost/ci_nusoap/index.php/soap_server/wsdl
Step 5 :
we are almost done.
now create soap_client.php in “application/controllers/” and add below code in “application/controllers/soap_client.php”
<?php
class Soap_client extends CI_controller {
function __construct() {
parent::__construct();
$this->load->library(“Nusoap_lib”);
$this->load->helper(“url”);
}
function index() {
$this->soapclient = new soapclient(site_url(‘Bills_WS/index/wsdl’), true);
$err = $this->soapclient->getError();
if ($err) {
echo ‘<h2>Constructor error</h2><pre>’ . $err . ‘</pre>’;
}
$result = $this->soapclient->call(‘hello’, array(‘name’ => ‘Scott’));
// Check for a fault
if ($this->soapclient->fault) {
echo ‘<h2>Fault</h2><pre>’;
print_r($result);
echo ‘</pre>’;
} else {
// Check for errors
$err = $this->soapclient->getError();
if ($err) {
// Display the error
echo ‘<h2>Error</h2><pre>’ . $err . ‘</pre>’;
} else {
// Display the result
echo ‘<h2>Result</h2><pre>’;
print_r($result);
echo ‘</pre>’;
}
}
}
}
Access Soap Client Now
http://localhost/ci_nusoap/index.php/soap_client