Web Services Platform Architecture
XML along with HTTP forms the basis of web services. XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions. The HTTP protocol is the most used Internet protocol.
Web services platform consists of the following components:
- UDDI (Universal Description, Discovery and Integration)
- WSDL (Web Services Description Language)
- SOAP (Simple Object Access Protocol)
UDDI (Universal Description, Discovery and Integration) is a platform-independent, XML based registry service where companies can register and search for Web services.
- UDDI is a directory for storing information about web services
- UDDI communicates via SOAP
- UDDI is a directory of web service interfaces described by WSDL
WSDL (Web Services Description Language) is an XML-based language for locating and describing Web services. WSDL definition describes how to access a web service and what operations it will perform along with the message format and protocol details for the web service. WSDL is a W3C standard.
A sample WSDL for a stock quote service is available at http://www.webservicex.net/stockquote.asmx?WSDL.
SOAP (Simple Object Access Protocol) is an XML-based communication protocol for exchanging structured information between applications over HTTP, SMTP or any other protocol. In other words, SOAP is a protocol for accessing a Web Service.
SOAP Message Structure
A SOAP message is an ordinary XML document containing the following elements:
- An Envelope (required) element that identifies the XML document as a SOAP message
- An optional Header element that contains header information
- A Body (required) element that contains call and response information
- An optional Fault element containing errors and status information
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> ... </soap:Header> <soap:Body> ... <soap:Fault> ... </soap:Fault> </soap:Body> </soap:Envelope>
Example SOAP Request and Response Message
Below is a sample SOAP Request message for a Stock Quote service whose WSDL is available at http://www.webservicex.net/stockquote.asmx?WSDL. The message is sent as a HTTP Post Request whose content is nothing but a SOAP Request message. The soap request message contains a soap envelope and a soap body with a stock quote request for stock symbol “GOOG” (Google).
POST /stockquote.asmx HTTP/1.1 Content-type: text/xml;charset="utf-8" Soapaction: "http://www.webserviceX.NET/GetQuote" Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 User-Agent: JAX-WS RI 2.1.6 in JDK 6 Host: localhost Connection: keep-alive Content-Length: 194 <?xml version="1.0" ?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <GetQuote xmlns="http://www.webserviceX.NET/"> <symbol>GOOG</symbol> </GetQuote> </S:Body> </S:Envelope>
Below is a sample SOAP Response message for the above request. Apart from the HTTP response headers the content is a SOAP response message with a soap envelope and a soap body. The result is enclosed within “GetQuoteResponse” tag. The last traded price for stock symbol “GOOG” (Google) is in “last” tag put at $594.34 on 5/29/2012 04:00PM.
HTTP/1.1 200 OK Cache-Control: private, max-age=0 Content-Length: 975 Content-Type: text/xml; charset=utf-8 Server: Microsoft-IIS/7.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 30 May 2012 09:14:05 GMT <?xml version="1.0" encoding="utf-8"?> <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> <StockQuotes> <Stock> <Symbol>GOOG</Symbol> <Last>594.34</Last> <Date>5/29/2012</Date> <Time>4:00pm</Time> <Change>0.00</Change> <Open>N/A</Open> <High>N/A</High> <Low>N/A</Low> <Volume>100</Volume> <MktCap>193.8B</MktCap> <PreviousClose>594.34</PreviousClose> <PercentageChange>0.00%</PercentageChange> <AnnRange>473.02 - 670.25</AnnRange> <Earns>32.998</Earns> <P-E>18.01</P-E> <Name>Google Inc.</Name> </Stock> </StockQuotes> </GetQuoteResult> </GetQuoteResponse> </soap:Body> </soap:Envelope>
Web Services Architecture
- Service Discovery: This part of the architecture is responsible for centralizing services into a common registry and providing easy publish/search functionality. UDDI handles service discovery.
- Service Description: One of the most interesting features of Web Services is that they are self-describing. This means that, once a Web Service is located, it will let us know what operations it supports and how to invoke it. This is handled by the Web Services Description Language (WSDL).
- Service Invocation: Invoking a Web Service involves passing messages between the client and the server. SOAP (Simple Object Access Protocol) specifies how we should format request messages to the server, and how the server should format its response messages.
- Transport: Finally, all these messages must be transmitted somehow between the server and the client. The protocol of choice for this part of the architecture is HTTP (HyperText Transfer Protocol) – the protocol used to access conventional web pages on the Internet. We could also use other protocols, but HTTP is currently the most used one.
How Web Services work?
- The Service Provider generates the WSDL describing the application or service and registers the WDSL in UDDI directory or Service Registry.
- The Service Requestor or client application which is in need of web service contacts the UDDI and discovers the web service.
- The client based on the web service description specified in the WSDL sends a request for a particular service to the web service application listener in SOAP message format.
- The web service parses the SOAP message request and invokes a particular operation on the application to process that particular request. The result is packed in an appropriate SOAP response message format and sent to the client.
- The client parses the SOAP response message and retrieves the result or error messages if any.
Server-side Components of Web Services Application
- Web service: This is the software or component that exposes a set of operations. For example, if we are implementing our Web service in Java, our service will be a Java class (and the operations will be implemented as Java methods). Clients will invoke these operations by sending SOAP messages.
- SOAP Engine: Web service implementation does not know anything about interpreting SOAP requests and creating SOAP responses. To do this, we need a SOAP engine. This is a piece of software that handles SOAP requests and responses. Apache Axis is an example of SOAP engine. The functionality of the SOAP engine is usually limited to manipulating SOAP.
- Application Server: To actually function as a server that can receive requests from different clients, the SOAP engine usually runs within an Application Server. This is a piece of software that provides a ‘living space’ for applications that must be accessed by different clients. The SOAP engine runs as an application inside the application server. A good example is the Apache Tomcat server – a Java Servlet and JSP container.
- HTTP Server: Many application servers already include some HTTP functionality, so we can have Web services up and running by installing a SOAP engine and an application server. However, when an application server lacks HTTP functionality, we also need an HTTP Server. This is more commonly called a ‘Web server’. It is a piece of software that knows how to handle HTTP messages. A good example is the Apache HTTP Server, one of the most popular web servers in the Internet.
Tags: soap, soap engine, uddi, web service server-side components, web services, web services architecture, web services components, web services flow, web services platform, working of web services, wsdl