Daily we spend so much time on web, doing R&D, playing games, chatting with friends, and much more. But rarely do we realize that behind these there are various services those allow us to communicate between different electronic devices over network. These services are called Web Services and to describe the functionalities offered by Web Services WSDLs are used, which describe structured communications by defining an XML grammar. This XML grammar describes network services as collections of various electronic devices capable of exchanging message. Hence Web Services are basically transportation of data in XML documents through open protocols.
So, first of all let us have a basic understanding of what XML is.!!
Extensible Markup Language (XML) was designed to transport and store data. It reduces the complexity of exchanging message between heterogeneous IT systems as it is hardware and software independent tool. XML data is stored in a text format hence it is easily upgraded to new versions of application or OS without losing any data.
Unlike HTML where all the tags are pre-defined, you can define your own tags hence this makes XML developer friendly. Though, these tags must be in tree format called XML tree which starts from the root and then branches and leaves. Let us understand the different elements of the XML tree through the following simple example (invitation.xml):
|<?xml version=”1.0” encoding=”ISO-8859-1”?> <invitation> <invite> <to>Jerry</to> <from>Tom</from> <date>28th August</date> <message>
You are invited to my Birthday Party
In the above example first line is the xml declaration which tells that the version of xml is 1.0 and encoding used is ISO-8859-1 which means West European character set. Clearly from above we can say that Tom is inviting jerry for his birthday party. <invitation> is the root element of the document which describes the whole document. <invite> is the parent element for which rest <to>, <from> and <message> are the child elements. Hence we can see that XML document is self descriptive. It should be kept in mind that tags are case sensitive and each tag must be closed and properly nested.
XML focuses on the content of data and its transportation but not on how data is displayed. It was created to structure, store, and transport information. But to display the XML data in the browser it must be designed, hence before displaying the data, it is transformed to HTML using XSLT (eXtensible Stylesheet Language Transformations). In general XSLT is a programming language that can transform one XML format into another XML format or into HTML or even into plain text.
Now lets write an XSLT code for the above XML example (invitation.xsl):
|<?xml version=”1.0″ encoding=”ISO-8859-1″?><xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:template match=”/”> <html> <body bgcolor=”pink”> <font size=”3″ color=”blue”> <xsl:for-each select=”invitation/invite “> Dear <xsl:value-of select=”to”/>, <p><xsl:value-of select=”message”/> on
<p>From <xsl:value-of select=”from”/><p>
Now the above code defines the display of the XML code written previously, which looks like:
I think now we have clear picture of XSLT. Here many people may conclude that XSLT is similar to CSS (Cascading Style Sheet), which is not at all correct. CSS just manipulates the way your content looks in a document whereas XSLT actually transforms one document to another.
Now we have XML Schema Definition (XSD) that describes the structure of an XML document and validates the same. By using XSDs proper hierarchy of the XML nodes can be checked, custom data types can be defined, minimum and maximum occurrence of the elements can be restricted, and many more. To understand it better lets consider the same XML code written in XML example above, and write the corresponding XSD (invitation.xsd):
|<xs:schema attributeFormDefault=”unqualified”elementFormDefault=”qualified”xmlns:xs=”http://www.w3.org/2001/XMLSchema”> <xs:element name=”invitation”> <xs:complexType> <xs:sequence> <xs:element name=”invite”> <xs:complexType> <xs:sequence> <xs:element name=”to” type=”xs:string” />
<xs:element name=”from” type=”xs:int” />
<xs:element name=”message” type=”xs:int” />
<xs:element name=”date” type=”xs:int” />
In first glance the above code may look bit complex but as we take a closer view we find that we are just defining each tag and their data types, so that the validation of the document in this format becomes easy. XSD just defines the building blocks of an XML document, i.e., the elements and attributes with their respective default values in it, specifies child elements and its number, etc.
Note that if you want to give XSD file reference in the corresponding XML file which is to be validated, you just have to modify the few things in the root element tag as:
(Here xsd_file_location is the physical or logical path where the XSD file is located).
Hence XML is an open technology which is used for the storage or transportation of data even between highly incompatible systems that are exchanging messages. It is not affected by the hardware or software used by these systems. Thus, XML play a basic role in the working of Web Services.
What are Web Services?
Now days nearly all the web architectures are service oriented. To understand Web Services better let’s take an example of Flipkart ( www.flipkart.com ) .
Suppose you want to purchase a mobile. You enter mobile brand you want to look for and search category as mobile and accessories. You specify your search criteria through one service, which communicates with another service to find out the list of mobiles of that brand. As you select the mobile to buy, your order and relevant details are submitted to another service which calculates your total expense and redirects you for online payment. After payment you get the confirmation mail for the order through another service. The entire process, from initial search to getting confirmation mail and further order status mails, are managed by different types of communication between various web services.
Hope you had a rough idea what exactly are web services. In short any services that run on web are Web Services. These are good fit when we have multi-channel applications or we need to integrate between heterogeneous IT systems. This is because they are interoperable and provide loose coupling.
Web Services communicate using open protocols. Basic Web Services combine the power of two universal technologies: XML, the universal data description language; and the HTTP transport protocol widely supported by different browsers and web servers.
In short we can say that,
|Web Services = XML + transport protocol|
Web Services have three basic platform elements:
- SOAP (Simple Object Access Protocol): It is an XML based lightweight protocol for exchange of information in a decentralized, distributed environment. Read more on SOAP here.
- WSDL (Web Services Description Language): It is an XML format for describing Web Services as a set of endpoints exchanging message.
- UDDI (Universal Description, Discovery and Integration): It is an XML-based registry for businesses worldwide to list themselves on the Internet.
Now Let us have look at the working of Web Services:
In the above diagram in the first step both the entities get known to each other and have an agreement of semantics and the service description that will take care of interactions between them. Now both the agents exchange message through SOAP.
Here we have one more agent called Discovery Agent which does the registry. Now whenever a Provider creates a web service, it publishes the corresponding WSDL for it. So when next time Requestor needs that service it will first check for the corresponding WSDL in UDDI. If it is present there it will directly use it to invoke the provider’s web service, but if it is not there it requests for the WSDL from the Provider Agent.
Thus Web Service is a software application identified by URI, whose interfaces and bindings are capable of being defined, described, and discovered as XML artifacts. They support direct interactions with other software agents using XML-based messages via Internet-based protocols. So next time when you use web applications you know that you are invoking a web service which invokes another one and so on.