Q-1 What is web services? How it integrates and implements in industrial projects?
A web service is a standard used for exchanging information between applications or systems of heterogeneous type.
Software applications written in various programming languages and running on various platforms can use web services to exchange information over Internet using http protocol.
Why Web Service?
Expose method as a service over network:
- Web service is a chunk of code written in some programming language (Say C# or Java) that can be invoked remotely through http protocol.
- Once the Web methods are exposed publically, any applications can invoke it and use the functionality of the web methods.
Application Inter-operability – Connect heterogeneous applications:
- With the help of web service, heterogeneous applications (Java and PHP application) can communicate with each other
- Web service written in Java can be invoked from PHP by passing the required parameters to web methods.
- This makes the applications platform and technology independent.
- Web Services uses standardized industry standard protocol for the communication which must be adhered and followed by the applications creating Web Service.
Cost effective communication:
- Web service is using SOAP over HTTP protocol for communication which is much cheaper than systems like B2B.
RESTFul Webservice Request and Response – Drill down
- Fist step in designing RESTFul webservice is choosing the right domain name – say weatherinfo.org to retrieve weather information of cities
- Let us take the first example (weatherinfo.org) which takes city name as input, composes weather information of the city and respond back to the browser.
- Assume the response is in XML format, this can be in other formats like JSON as well.
- Here is the structure of Request and Response:
HTTP Request The client request from the browser will look like:
GET http://weatherinfo.org/getweather/mumbai HTTP/1.1
HTTP Response The server response will look like
HTTP/1.1 200 Ok
Date: Mon, 14 Apr 2014 10:20:58 GMT
<City name="Mumbai" datetime="2014-04-14 10:20:58 GMT" > <Condition>Scattered Clouds</Condition> <Temp>33</Temp> </City>
- Line 1 is the initial line which has the HTTP response code – 200 OK, lines 2 through 4 are the HTTP headers, line 5 is the mandatory blank line separating header and body, and lines 6 through 10 constitute the “HTTP Body (or content)” – this part is the data that the response carries and can be in any format, not necessarily XML.
Q-2 list out Advantages of using RESTful webservice.
- RESTful Web services are designed with less dependence on proprietary middleware (for example, an application server) than the SOAP- and WSDL-based kind.
- The great fit between Ajax and REST has increased the amount of attention REST is getting these days
- Exposing a system’s resources through a RESTful API is a flexible way to provide different kinds of applications with data formatted in a standard way. It helps to meet integration requirements that are critical to building systems where data can be easily combined (mashups) and to extend or build on a set of base, RESTful services into something much bigger.