First of all I would like to say that it is a very very simple thing.
But most of the beginners get afraid about the concept web services.Acctually it is nothing!!!.
It is only just request and response.
I will show you the correct and the easy way to do this.And you will understand how easy it is...
Before start let me say you few things about web services.
What are 'Web Services' ?.
Web service is used to communicate with two separate parties exchanging the data.
HTTP and XML is the basis for Web services.
Web services communicate using open protocols.
Web services can be used by other applications.
Following image will tell something more about it.
Step 01.
Here I use Codeigniter to do this.
What you need is to create a virtual Server Application.
Download the codeigniter from its website and save it as 'mytestwebserver' in your localhost folder[htdocs in XAMPP and www in WAMP] .
The server application is going to implement at there.
Step 02.
Here I use Nusoap toolkit to create the web server.
Download the nusoap toolkit from below link.
http://sourceforge.net/projects/nusoap/
Step 03.
After downloading NuSOAP toolkit, copy “lib” folder in “application/library/” folder.
Step 04.
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.
<?php
class Nusoap_library
{
function Nusoap_library()
{
require_once('lib/nusoap'.EXT);
}
}
?>
Step 05
Create the controller as Mysoapserver.php and save the below codes.
<?php
class Mysoapserver extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library("Nusoap_library");
}
public function server(){
$ns="http://localhost/mytestwebserver/index.php/Mysoapserver/server";
$server=new nusoap_server;
$server->configureWSDL('MyService',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
$input_array = array ('count' => 'xsd:integer', 'type' => "xsd:string"); // method parameters
$return_array = array ("fruit" => "xsd:string");
$server->register(
'fruits',
$input_array,
$return_array,
"urn:SOAPServerWSDL",
"urn:".$ns."/fruits",
"rpc",
"encoded",
"Fruit Types"
);
function fruits($count,$type){
switch($type){
case 'red':
return $count." Applekkkk";
break;
case 'yellow':
return $count." banana";
break;
}
}
$server->service(file_get_contents("php://input"));
}
}
?>
Step 06: That is all of creating web server application as I use localhost[WAMP/XAMPP]
Use this urls in address bar to have below outputs.
Web Service URL: http://localhost/mytestwebserver/index.php/Mysoapserver/server
WSDL URL: http://localhost/mytestwebserver/index.php/Mysoapserver/server?wsdl
Now you have done the half of the work.Now server part is ok. Now it is need to have client part.. Step 01. Download the codeigniter from its website and save it as 'mytestwebclient' in your localhost folder[htdocs in XAMPP and www in WAMP] . The client application is going to implement at there. Step 02. Here I use Nusoap toolkit to create the web server. Download the nusoap toolkit from below link. http://sourceforge.net/projects/nusoap/ Step 03. After downloading NuSOAP toolkit, copy “lib” folder in “application/library/” folder. Step 04. 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. <?php class Nusoap_library { function Nusoap_library() { require_once('lib/nusoap'.EXT); } } ?> Step 05. Create a controller as MyClient.php and save below codes. <?php class MyClient extends CI_Controller{ function index(){ $client=new nusoap_client("http://localhost/mytestwebserver/index.php/Mysoapserver/server?wsdl"); // $client=new nusoap_client("http://localhost/Webser/index.php/Mysoapserver/server?wsdl"); //$ns="http://127.0.0.1/Webser/index.php/Mysoapserver/server"; $response=$client->call('fruits',array("count" => 4, "type" => "yellow")); echo $response."<br>"; echo "<h2>Request</h2>"; echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>"; echo "<h2>Responses</h2>"; echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>"; // echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>'; } } ?> Step 06 : Add this to autoload.php in config folder. $autoload['libraries'] = array('database', 'session', 'xmlrpc','email','Nusoap_library'); That is all now you can try to send a request from client to server application using below url. http://localhost/mytestwebclient/index.php/Myclient If it works it will give below outputs. That is all in next tutorial I will describe the functionality of this. :) |