Sunday, August 14, 2011

Web Service

Hi guys,
After some time I feel to write some thing here. This time I write my experiences and the knowledge I gain during my intern period. Now a days I am working at Cambio Healthcare Systems, Colombo 03.
So I am sharing my experience here. Hope there's something you to get.

What is a Web Service

A Web service contains some classes, interfaces, enumerations and structures which provide black box functionality to remote clients. Lets call that as a business object that execute unit of work (e.g. - Adding two numbers). So when client needs to get done the addition, he just send SOAP request over HTTP with two numbers, then WS(Web Service) sends back the result a, SOAP response, over HTTP. In WS, XML (Extensible Markup Language) is used to code & decode data and SOAP (Simple Object Access Protocol) to let applications exchange information over HTTP.

In ws XML, SOAP, WSDL and UDDI are the main things to consider. These are the protocols, languages and directory service used in web service. So let us see what's their role in web service.

XML - Stands for Extensible Markup Language and this markup language is much like HTML. This language is designed to transport and store data, and xml is self-descriptive.

SOAP - Stands for Simple Object Access Protocol: This is a communication protocol format for sending messages, and this is designed to communicate via internet and SOAP is platform independent as well as language independent. SOAP is based on XML and it is simple and extensible.

WSDL - Stands for Web Service Description Language. This is also based on XML, and used to describe and locate the web services.

UDDI - Stands for Universal Description, Discover and Integration. This is a directory service where companies can register and search for web services. The directories for storing information about web services. The communication to UDDI is done via SOAP.

I think that is enough to get and idea about the protocols and languages uses in web services. Now let us see, how these things get together and make a web service.

How Web Service - Client works?

The above picture clearly shows you, that how a client get done something from a web service.

Further more I will explain how does the client invoke web service in the web server.In step 4. web server sends the wsdl file which contains all the details about the required web service. That is why it is called web service description language. So according to that, the client can send a SOAP request (Step 5) using HTTP to invoke the method which he wants to invoke. Then it replied with the SOAP response using HTTP.

The next thing we should understand in web service is STUB.

Imagine our web service gives the addition when a client gives two integers

int add(int a, int b){

return a+b;


Web services can be created using two methods: top-down development and bottom-up development. Bottom-up Web services development involves creating a Web service from a Java™ bean or enterprise bean.

When creating a Web service using a bottom-up approach, first thing we should do is creating the JavaBean or EJB bean and then create the WSDL file and Web service. Actually most of the IDEs facilitate a wizard to generate this WSDL file based on the written java bean.

Going back to our example, in WSDL file the method 'add' is described. Then using this wsdl file we need to generate the software called stub. The good news is that there are plenty of tools available (as I mentioned earlier) that will generate client stubs based on the WSDL file of the web service.

Further more though there are lot of protocols and languages floating around, Web Services programmers usually never write a single line of SOAP or WSDL. Once we've reached a point where our client application needs to invoke a Web Service, we hand over that task the STUB .

So in our example, the client stub which was generated based on wsdl, facilitates to invoke the 'add' method in the web service, through a method which accepts two integers.

The following diagram shows you clearly that, what is the role of the stub in the play of Web Service

1. When client needs to invoke the web service, it calls the client stub. The client stub will turn this local invocation into a proper SOAP request. This is called marshaling or serializing process.

2. The SOAP request is sent over a network using HTTP. Web service container receives SOAP request and hand over to the server stub. Server stub converts the SOAP request in to something the server implementation can understand. This is called un-marshaling or de-serializing .

3. Service implementation receives the request from the server stub and carries out the work it has been asked to [ int add(int a, int b) ].

4. Result of the requested operation is handed to the server stub which will turn in to a SOAP response.

5. SOAP response is sent over a network using HTTP. Client stub receives the SOAP response and turn in to something the client application can understand.

6. Finally the application receives the result of the web service invocation.

This is where I work,

View Larger Map
And I should be Thankful to Mr. Lakshiri Dasun (Software Engineer) who is my supervisor at Cambio+.