WEB SERVICES From Chapter 19 of Distributed Systems
WEB SERVICES From Chapter 19 of Distributed Systems Concepts and Design, 4 th Edition, By G. Coulouris, J. Dollimore and T. Kindberg Published by Addison Wesley/Pearson Education June 2005 1
WEB SERVICES Topics • Introduction • Web Services • SOAP (Simple Object Access Protocol) Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 2
WEB SERVICES Introduction § A web service provides a service interface enabling clients to interact with servers in a more general way than web browsers do. § Clients access the operations in the interface of a web service by means of requests and replies formatted in XML and usually transmitted over HTTP. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 3
WEB SERVICES Introduction § Users require a secure means for creating, storing and modifying documents and exchanging them over the Internet. § The secure channels of TLS do not provide all of the necessary requirements. § XML security is intended to breach this gap. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 4
WEB SERVICES Introduction § Web services provide an infrastructure for maintaining a richer and more structured form of interoperability between clients and servers. § They provide a basis whereby a client program in one organization may interact with a server in another organization without human supervision. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 5
WEB SERVICES Introduction § External data representation and marshalling of messages exchanged between clients and web services is done in XML. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 6
WEB SERVICES Introduction § The SOAP (Simple Object Access Protocol) specifies the rules for using XML to package messages, for example to support a request-reply protocol. § Figure 1 summarizes the main points about the communication architecture in which web services operate. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 7
WEB SERVICES Introduction Figure 1. Web services infrastructure and components Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 8
WEB SERVICES Introduction § A web service is identified by a URL and can be accessed by clients using messages formatted in XML. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 9
WEB SERVICES Introduction § SOAP is used to encapsulate these messages and transmit them over HTTP or another protocol, for example, TCP or SMTP. § A web service generally provides a service description, which includes an interface definition and other information, such as the server's URL. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 10
WEB SERVICES Web Services § A web service interface generally consists of a collection of operations that can be used by a client over the Internet. § The operations in a web service may be provided by a variety of different resources, for example, programs, objects, databases. § A web service may either be managed by a web server along with web pages; or it may be a totally separate service. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 11
WEB SERVICES Web Services § Many well-known commercial web services including Amazon, Yahoo, Google and e. Bay offer web service interfaces that allow client to manipulate their web resources. § As an example, the web service offered by Amazon. com provides operations to allow clients to get information about products, to add an item to a shopping cart or to check the status of a transaction. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 12
WEB SERVICES Web Services § The Amazon web services may be accessed either by SOAP or by REST (REpresentaional State Transfer). § The provision of a service interface allows its operations to be combined with those of other services to provide new functionality. Figure 2. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 13
WEB SERVICES Web Services Figure 2. The ‘travel agent service’ combines other web services Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 14
WEB SERVICES Web Services § A major task of many middleware platforms is to protect the programmer from the details of data representation and marshalling and sometimes with making remote invocations look like local ones. § These things are provided as a part of an infrastructure or middleware platform for web services. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 15
WEB SERVICES Web Services § At the simplest level, clients and servers may read and write their messages directly in SOAP, using XML. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 16
WEB SERVICES SOAP (Simple Object Access Protocol) § SOAP is defined to enable both clientserver and asynchronous interaction over the Internet. § It defines a scheme for using XML to represent the contents of request and reply messages as well as a scheme for the communication of documents. § Originally, SOAP was based on HTTP, but the current version is designed to use a variety of transport protocols including SMTP, TCP or UDP. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 17
WEB SERVICES SOAP (Simple Object Access Protocol) § The SOAP specification states: Ø How XML is to be used to represent the contents of individual messages. Ø How a pair of single messages can be combined to produce a request-reply pattern. Ø The rules as to how the recipients of messages should process the XML elements that they contain. Ø How HTTP and SMTP should be used to communicate SOAP messages. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 18
WEB SERVICES SOAP (Simple Object Access Protocol) § A SOAP message is carried in an “envelope”. § Inside the envelope there is an optional header and a body as shown in Figure 3. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 19
WEB SERVICES SOAP (Simple Object Access Protocol) Figure 3. SOAP message in an envelope Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 20
WEB SERVICES SOAP (Simple Object Access Protocol) § Message headers can be used for establishing the necessary context for a service or for keeping a log or audit of operations. § The message body carries an XML document for a particular web service. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 21
WEB SERVICES SOAP (Simple Object Access Protocol) § The XML elements envelope, header and body, together with other attributes and elements of SOAP messages are defined as a scheme in the SOAP XML namespace. § Figure 4 shows an example of a simple request message without a header. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 22
WEB SERVICES SOAP (Simple Object Access Protocol) Figure 4. Example of a simple request without headers Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 23
WEB SERVICES SOAP (Simple Object Access Protocol) § Figure 5 shows the corresponding successful reply messages, which contains the two output arguments. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 24
WEB SERVICES SOAP (Simple Object Access Protocol) Figure 5. Example of a reply corresponding to the request in Figure 4 Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 25
WEB SERVICES SOAP (Simple Object Access Protocol) § A transport protocol is required to send a SOAP message to its destination. § SOAP messages are independent of the type of transport used- their envelopes contain no reference to the destination address. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 26
WEB SERVICES SOAP (Simple Object Access Protocol) § Figure 6 illustrates how the HTTP POST method is used to transmit a SOAP message. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 27
WEB SERVICES SOAP (Simple Object Access Protocol) Figure 6. Use of HTTP POST Request in SOAP client-server communication Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 28
WEB SERVICES SOAP (Simple Object Access Protocol) § The HTTP headers and body are used as follows: Ø The HTTP headers specify the endpoint address (the URI of the ultimate receiver) and the action to be carried out. Ø The HTTP body carries the SOAP message. § As HTTP is a synchronous protocol, it is used to return a reply containing the SOAP reply, as shown in Figure 5. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 29
WEB SERVICES SOAP (Simple Object Access Protocol) § Figure 7 shows a web service interface. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 30
WEB SERVICES SOAP (Simple Object Access Protocol) package Shape. List. Service; import java. rmi. *; public interface Shape. List extends Remote { int new. Shape(Graphical. Object g) throws Remote. Exception; int number. Of. Shapes()throws Remote. Exception; int get. Version() throws Remote. Exception; int get. GOVersion(int i)throws Remote. Exception; Graphical. Object get. All. State(int i) throws Remote. Exception; } Figure 7. Java web service interface Shape. List Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 31
WEB SERVICES SOAP (Simple Object Access Protocol) § The Java interface of a web service must conform to the following rules, some of which are illustrated in Figure 7: Ø It must extend the Remote interface. Ø It must not have constant declarations, such as public final static. Ø The methods must throw the java. rmi. Remote. Exception or one of its subclasses. Ø Method parameters and return types must be permitted JAX-RPC types. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 32
WEB SERVICES SOAP (Simple Object Access Protocol) § The class that implements the interface Shape. List is shown in Figure 8. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 33
WEB SERVICES SOAP (Simple Object Access Protocol) package Shape. List. Service; import java. util. Vector; public class Shape. List. Impl implements Shape. List{ private Vector the. List = new Vector(); private int version = 0; private Vector the. Versions = new Vector(); public Shape. List. Impl(){ version = 0; the. Versions = new Vector(); } public int new. Shape(Graphical. Object g) { version++; the. List. add. Element(g); the. Versions. add. Element(new Integer(version)); return the. List. size(); } public int number. Of. Shapes(){ return the. List. size(); } public int get. Version() { return version; } public int get. GOVersion(int i){ return ((Integer) the. Versions. element. At(i)). int. Value(); } public Graphical. Object get. All. State(int i) { return (Graphical. Object)the. List. element. At(i); } } Figure 8. Java implementation of the Shape. Listserver Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 34
WEB SERVICES SOAP (Simple Object Access Protocol) § There is no main method, and the implementation of the Shape. List interface does not have a constructor. § In effect, a web service is a single object that offers a set of procedures. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 35
WEB SERVICES SOAP (Simple Object Access Protocol) § Figure 9 shows the Shape. List client main a call through a proxy. Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 36
WEB SERVICES SOAP (Simple Object Access Protocol) package staticstub; import javax. xml. rpc. Stub; public class Shape. List. Client{ public static void main(String args[]){ try{ Stub stub = create. Proxy(); stub. _set. Property (javax. xml. rpc. Stub. ENDPOINT_ADDRESS_PROPERTY, args[0]); a. Shape. List = (Shape. List) stub; System. out. println("Got stub"); int n = a. Shape. List. number. Of. Shapes(); System. out. println("Number of shapes=" + n); int v = a. Shape. List. get. Version(); System. out. println("Version=" + v); Vector s. List = new Vector(n); for(int i=0; i<n; i++){ System. out. println("shape no =" + i); Graphical. Object g = a. Shape. List. get. All. State(i); System. out. println("Got shape " + i); int vers = a. Shape. List. get. GOVersion(i); s. List. add. Element(g); System. out. println("Version number " + vers); g. print(); } Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 37
WEB SERVICES SOAP (Simple Object Access Protocol) Graphical. Object g = new Graphical. Object(shape. Type, 30, 40, 3300, 5500, true); System. out. println("Created graphical object"); int list. Length = a. Shape. List. new. Shape(g); System. out. println("Stored shape " + shape. Type); }catch(Exception e) {System. out. println("all. Shapes: " + e. get. Message()); } } private static Stub create. Proxy() { return (Stub) (new My. Shape. List. Service_Impl(). get. Shape. List. Port()); } } Figure 9. Java implementation of the Shape. Listclient Couloris, Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005 38
- Slides: 38