Today, I came to know about Web Services. I am gonna discuss what I learnt today.
What is a web service?
Web service is a piece if code that runs on the server all the time. I will give an example of MakeMyTrip for the better understanding of concept and it’s usage. MakeMyTrip provides online travel services including flight tickets, domestic, hotel reservations, rail and bus tickets, etc. Let’s talk about flight tickets. This website shows the status of seats availability and prices of airline companies like Air India, Go Air, Jet airways etc. So, the question comes how MakeMyTrip has that information that is stored in different airline companies’ databases. Their is no possibility that MakeMyTrip has access to their databases since it is a privacy concern. So, what happens actually is, all the airline companies create web services and provide the API’s to access those web services by invoking the methods in web service class with suitable parameters.
I hope you got an idea of why there comes a need of web service. Besides this examples, there are so many examples in the world where we can see web services coming into picture; like Trivago that compares prices and features of different hotels in a place.
Behind the scene:
Now, I am gonna tell about how the communication takes place between the client and server. From my MakeMyTrip example, you can consider MakeMyTrip as a Client and other airline companies’ web application as server or you say service provider. So, how the communication is happening-
- At server-side, web service is created. This is nothing but a class having business methods that client may invoke.
- After web service is created, the information about this web service is stored in WSDL(Web Services Description Language) file which is XML based. This file contains information such as methods in web service, their parameters, return type etc.
XML is universal language that is platform and language independent. XML is used because the communicating web applications may be built in different languages and working on different platforms.
This WSDL file is generated by WSDL generation tool. - Server also provides the endpoint information which is nothing but the URL of web-service denoting it’s location.
- Now, question comes, how client comes to know about WSDL file. For that, WSDL file is registered in UDDI(Universal Description, Discovery, and Integration) registery where WSDL files are registered with unique names.
- Now, come to client side. Client now requests UDDI which will provide requested WSDL file.
- Client then generates Stub/proxies. This is actually generated by Stub generation tool. Stub is just a class having same methods as we had in web-service of server but having different implementation of the methods.
One more thing, if client application is made in Java, the Stub class is also in Java; meaning in whatever language client web application is made, in the same language Stub class is generated. - Now, when client has to invoke any method of web service, it’s gonna create object of Stub by passing the required parameter values.
- Stub, then stores this information(method, parameter values) in XML document. Now, a SOAP request is generated using this XML file.
- HTTP protocol now transfers the soap request from client to server.
- At server, their is another program Skeleton which is predefined class. Skeleton class is made using same language as server web application is made.
Skeleton reads the SOAP request(XML) which has arrived and passes the parameter values to the actual method in web service. - Then, Skeleton prepares the XML document which is nothing but SOAP response containing the response from invoked method.
- HTTP again transfers the SOAP request from server to client and handed over to Stub.
- Response is read by Stub and given shown to client.
I mentioned about WSDL generation tool and Stub generation tool. These tools are provided by API’s such as JAX-RPC, JAX-WS, JAX-RS. These API’s are provided by Sun Microsystems if we are creating web application in Java.
I referred this video for the above explanation.




