Web Services Tutorial – Part 1

Web Services are typically services offered through web via exchange of XML data. A client makes a request call and server provides a response for the service call. This does not have a GUI it is mainly used for exchanging business logic. This is similar to the services provided by Object Management Group’s Common Object Request Broker Architecture (CORBA), Microsoft’s Distributed Component Object Model (DCOM), Sun’s Java Remote Method Invocation (RMI)

The Web Services uses the following components/protocols

XML – eXtensible Mark-up Language, used for defining the request and response data.

SOAP – Simple Object Access Protocol, a platform independent protocol used by the client and sever to make a Remote Procedure Call (RPC)

WSDL – Web Services Definition Language, describes the service and its operations

UDDI – Universal Description Discovery and Integration, for listing the web services.

Web_Services

Key Features of Web Services

  1. Can be accessed via Web
  2. Interoperable – Services can be accessed irrespective of the programming language or Operating System
  3. XML Communication – It is simple and less time consuming.
  4. Supports loosely coupled connections.

To get a better understanding of a web service, we can look at the stock quote web service available here (http://www.webservicex.net/stockquote.asmx)

This web service provides share price for a given stock quote. To see the Web Service Definition Language the URL needs to appended with ?wsdl

 http://www.webservicex.net/stockquote.asmx?wsdl

WSDL for stock quote web service looks as shown below

Stock Quote Service WSDL

The WSDL provides the services description like the operations details(GetQuote) provided by the Stock Quote Service. Let us check this with by making a request for stock symbol GOOG (Google)

SOAP Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:GetQuote>
         <web:symbol>GOOG</web:symbol>
      </web:GetQuote>
   </soapenv:Body>
</soapenv:Envelope>

SOAP Response

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <GetQuoteResponse xmlns="http://www.webserviceX.NET/">
         <GetQuoteResult><![CDATA[<StockQuotes> 
             <Stock> 
               <Symbol>GOOG</Symbol>
               <Last>392.77</Last>
               <Date>5/13/2009</Date>
               <Time>10:57am</Time>
               <Change>-6.24</Change>
               <Open>394.09</Open>
               <High>396.39</High>
               <Low>391.35</Low>
               <Volume>924608</Volume>
               <MktCap>124.1B</MktCap>
               <PreviousClose>399.01</PreviousClose>
               <PercentageChange>-1.56%</PercentageChange>
               <AnnRange>247.30 - 591.19</AnnRange>
               <Earns>13.679</Earns>
               <P-E>29.17</P-E>
               <Name>Google Inc.</Name>
             </Stock>
           </StockQuotes>]]></GetQuoteResult>
      </GetQuoteResponse>
   </soap:Body>
</soap:Envelope>

The above the SOAP Request makes a service call for the stock symbol GOOG and SOAP Response provides the stock details such as Last Price, Low, high, Change, Previous Close etc.

In Category: Programming

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 0 Comments
No comments yet. Be the first.

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.