|
Web Services – Web server’s Methods
Web services are the services managed by web server. Web services allow us to share logic (or data) across many platforms and hardware configurations. For example, you can create a Java web service and someone else can consume it using a PHP client without having to learn single line of Java code. So web services are platform independent and language independent.
Web pages developed for end users and Web services developed for Programmers.
There are many available scripting languages that support web services. PHP is one such language, with a powerful open source functions and tools.
Uses:
Assume you have two websites; one is developed with ASP.NET and another with PHP. And you have good script (or logic) available in PHP for currency conversion or temperature converter etc., that is not available in .NET. But you want the same functionality in both the websites. Now you should create one service in PHP website, Web service is nothing but a function. So you can register one function with necessary parameters for currency conversion or temperature conversion etc., and uploaded in your PHP hosting server.
Now the .NET client can call that particular function with passing the necessary parameters. The Web service which resides in PHP hosting server would receive the request and process the request and send the output to the .NET client. Finally the .NET application will get the output.
Here .NET application uses the PHP Application Logic. The same logic should be used by any of programming language which supports web services. There are many available scripting languages that support web services. PHP is one such language, with a powerful open source functions and tools.
You can rise one question here i.e what is the matter if any unknown person knows your webservice means what type of security available to restrict your webservice access by unknown persons. The solution is there are some security procedures available to prevent your webservice from unauthorised access. The most used security procedures are
Domain name restriction
IPAddress restriction
So you can allow only some IPAddresses or domains to access your webservice. Ex: Deny all, allow 192.168.0.100 and Deny all, allow inkakinada.com,nyros.com etc.,
Roles of SOAP and XML:
Web services send and receive data in the form of Extensible Markup Language (XML), which travel via Simple Object Access Protocol (SOAP).
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.
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.
SOAP [Simple Object Access Protocol]: It a transport protocol for the client request to the web service and response to the client from web service.
SOAP Message Structure for request and response for webservice which calculates sum of two numbers:
Request from client to webservice
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:header>
----
</soap:header>
<soap:body>
<sum>
<a>10</a>
<b>20</b>
</sum>
</soap:body>
</soap:Envelope>
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
Response from web service to client request
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:header>
----
</soap:header>
<soap:body>
<response>
<output>30</output>
</response>
</soap:body>
</soap:Envelope>
Examples:
IP2Location
Remote database accessing etc.,
Alternatives:
We can use XMLRPC [XML Remote Procedure Call] for remote data processing [or accessing].
|