Thursday, February 10, 2011

Why use XML in Webservices

The importance of communication in our day to day life can never be understated. We need to communicate between ourselves in order to have any “meaningful” interaction. Analogously computers also need to “communicate” between each other in order to have a meaningful interaction.

Communication is always wonderful until we come across a situation where we need to communicate with people who don’t understand our language and we don’t understand theirs.
For a computer program to “talk”, he needs to be able to call another program’s method/function.  Again this is great as long as the caller and callee are on the same platform, but once we talk of distributed computing such an assumption is outrageous if not downright stupid. Often we come across situations where we need to be able to call a PHP script from JAVA, .NET function from JAVA, COBOL procedures from JAVA and vice versa.

This is similar to 4 guys talking in 4 different languages (let’s say Hindi, Chinese, German and French) trying to ask a question each. We can’t really communicate with each other till either

   a)      We have an interpreter who knows all the four languages and translates amongst us
   b)      We all know a common language (let’s say English)

Translating the above solution to our similar predicament with computers, the computing world provides us with 2 similar solutions:

    a)      Object Request Broker (ORB)
    b)      XML

To quote from Wikipedia: “In distributed computing, an object request broker (ORB) is a piece of middleware software that allows programmers to make program calls from one computer to another via a network. ORBs promote interoperability of distributed object systems because they enable users to build systems by piecing together objects from different vendors, so that they communicate with each other via the ORB.”
To put in simple words, an ORB is our interpreter. The main task of the ORB can be highlighted as below:

   a)      Convert the “method call request” from the language of requester (this includes serializing custom data
             types, method name to be called)
   b)      Convert into bytes and transfer over the network
   c)       Re-convert the bytes into the language understood by the requested function (and reverse the bytes
             into the data types understood by the called language).

Some of the common implementations of ORB are CORBA, RMI (inter java communication), DCOM, .NET Remoting. The biggest challenge/limitation of an ORB is the complexity associated with its implementation.  I shall not go much into details of ORB but you can probably look up RMI and CORBA in any site.

XML is to computers what English is to humans. The usage of XML allows us to communicate between many different languages using a common and “simple to understand language” structure which is portable and independent of implementing technology. By itself XML has no meaning (it just a bunch of tags put together) however when put into a relevant context they contain a lot of information.
At expense of repeating myself the biggest advantage of XML are:

   a)      Interoperability
   b)      Technology independence
   c)       Portability

And it is this power of XML that is utilized in SOAP which will be topic of discussion in my next article.


  1. really gud article..
    post more things :)

  2. Appreciate .. explaining in pretty simple and common terms..