In June 2000, Microsoft coined the term “Web Services” when they introduced this as one of the key component of its .NET framework. As other industry players started adopting this, it was evident that this technology would revolutionize distributed computing in the coming years. In the past few years many techniques have been developed to help applications interact with each other, of which prominent one is Web Services by a large extend.
Spring Web Services (Spring WS) follows the strategy of contract-first web services. It focuses more on XML and lesser on Java implementation. The underlying details are completely under the control of developers starting from the contract to the marshalling/unmarshalling details to the endpoint which actually handles the request.
Spring WS being a product of the Spring Framework, offers first class support of using Spring configurations and integrating with Spring framework. It provides ability to plug-in various XML APIs (SAX, DOM, StAX, XOM, and JDOM) to handle XML messages and can always ensure that the XML contract is marshaled correctly into Java objects. It supports JAXB 1 and 2, Castor, XMLBeans, JiBX, and XStream as part of its XML marshalling support.
When you have finished with this Chapter, you will have clear idea of all the terminologies related to web services and will also have a clear idea of the support provided by Spring to create and use web services in your application.
What is a Web Service
A Web service is a method of communication between two electronic devices over the Web (Internet).
A Web service is a unit of managed code that can be remotely invoked using HTTP protocol which allows exposing the functionality of your existing code over the network which other application can use it.
To give you a better explanation of what a web service is, I would like to give you the exact working of web service pictorially shown in Figure 16-1 below.
Figure 16-1. Web service architecture
The various steps involved in actually consuming an already exposed web service can be summarized as below:
- The client (web service consumer), queries the UDDI registry to get the details of the service and to locate it in the network (Internet).
- The UDDI registry refers the web service requesting client to the WSDL document details.
- The requesting client accesses the WSDL document.
- The WSDL document gives all the relevant details of the requested web service to the client.
- The client now sends SOAP-message request to the actual web server exposing the service.
- The web service returns the SOAP-message response which the client receives and does the appropriate processing.
Spring hides many of the web service complexities away from the developer. But since some concepts are very crucial in overall understanding of web services, we’ll take a brief look at some these concepts in the following sections.
SOAP (Simple Object Access Protocol) is an XML vocabulary that lets programs on separate computers interact across a network via RPC (Remote Procedure Call). A SOAP message can be of three types summarized as below:
- Method call – it contains name of method and parameters.
- Method Response -contains the return values.
- Fault Message – if service throws exception, it produces SOAP fault message. Due to any reason if transport fails, it will give appropriate standard HTTP messages
The SOAP message structure is illustrated in Figure 16-2.
Figure 16-2. A typical SOAP message structure
Page Visitors: 9946