In a Normal web surfing scenario, a visitor visits a website and use the functionality provided by that particular website. User sends HTTP request to server from web browsers and server taken user’s request, processed and send response back to the user through browser. This is the process of website surfing by end user. Ex: www.inkakinada.com will provide lot of services to the end users like movies, news, jobs etc., information.
Overview
Here, we cant get the www.inkakinada.com services by visiting www.nyros.com . Am I right? But it is also possible with web services, the name it self gives the meaning. Services provided by web. What exactly means You don’t need to visit the particular website to use their service and functionality if they are providing web services
So Web services are used to share the resource among the websites.
What are web services?
Web services are the set of platform independent exposed functions which can be used to share logic (or data) across many websites, platforms and hardware configurations.
Hence web services are platform independent and language independent. Means JAVA web services can be used PHP Developers and vice versa.
There are two parties involved in web services, one is web service provider and other called web service consumer.
Uses of web services?
Exposing your existing functionality through out the web with no cost
Retrieve information dynamically over the web
Connecting Different Applications i.e Interoperability
No Cost for communication
How they implement?
There are different methods available for developing web services but below three are the most common methods
SOAP
XML–RPC
REST
SOAP is the best choice for PHP Developers to develop Web services
SOAP
SOAP is the acronym of Simple Object Access Protocol. It is a transport protocol for the client request to the web service and response to the client from web service.
Web services uses the language XML to encode and decode your data and used the transport protocol SOAP to transport xml data between client and server.
Nusoap is the toolkit of PHP for providing and consuming web services using SOAP in PHP .
XML
Web services send and receive data in the form of Extensible Markup Language (XML), which travel via Simple Object Access Protocol (SOAP).
XML [Extensible markup language] is a language which can be used for share information between different applications irrespective of platforms [windows / Linux etc] and languages [JAVA / PHP / .NET / ROR etc]. Hence XML is platform independent and language independent.
Why use PHP
Already a very popular for web development
XML support
CURL support
OOP
SOAP extension etc.,
Lot of important tools available freely
Sample Application
Here we implement one sample application which provides STD code for the city.
Assume one website which contains all the cities zip codes.
So he would like to provide this resources through out the web to the people who wants to find zip codes for the cities.
First he create one web service in his website.
Code for creating service
include("nusoap.php");
include("dbconfig.php");
$server = new soap_server();
$server->register("getSTD");
function getSTD($city)
{
$query="select * from cities where cityname=$city";
Soap transfer the request and response very securely.
Soap packed the message securely and called it as soap envelop which contains 3 parts as below
1. Soap header, 2. Soap body, 3. Soap fault
Soap header will contain any additional information to be send along with method call, like authentication information, security info etc, soap body will contain actual web service method call information with necessary parameters or result of method execution soap fault will contain error info
Alternate Methods
XML-RPC [Remote Procedure Call]
Another way of providing and consuming web services. It uses XML to encode and decode the remote procedure call along with it’s parameter. You can visit the official website www.xmlrpc.com to know more about XML-RPC.
REST
Representational State Trasfer(REST) is comparatively simpler method for providing and consuming web services. It is not necessary to use XML as a data interchange format in REST. To know more about REST visit http://www.crummy.com/writing/RESTful-Web-Services/
0 comments
Post a comment