Download presentation
Presentation is loading. Please wait.
Published byBruce Gibbs Modified over 9 years ago
1
WEB SERVICES 1 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
2
WEB SERVICES 2 Topics Introduction Web Services SOAP (Simple Object Access Protocol) Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
3
WEB SERVICES 3 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
4
WEB SERVICES 4 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
5
WEB SERVICES 5 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
6
WEB SERVICES 6 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
7
WEB SERVICES 7 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
8
WEB SERVICES 8 Introduction Figure 1. Web services infrastructure and components Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
9
WEB SERVICES 9 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
10
WEB SERVICES 10 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
11
WEB SERVICES 11 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
12
WEB SERVICES 12 Web Services Many well-known commercial web services including Amazon, Yahoo, Google and eBay 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
13
WEB SERVICES 13 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
14
WEB SERVICES 14 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
15
WEB SERVICES 15 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
16
WEB SERVICES 16 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
17
WEB SERVICES 17 SOAP (Simple Object Access Protocol) SOAP is defined to enable both client- server 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
18
WEB SERVICES 18 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
19
WEB SERVICES 19 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
20
WEB SERVICES 20 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
21
WEB SERVICES 21 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
22
WEB SERVICES 22 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
23
WEB SERVICES 23 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
24
WEB SERVICES 24 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
25
WEB SERVICES 25 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
26
WEB SERVICES 26 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
27
WEB SERVICES 27 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
28
WEB SERVICES 28 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
29
WEB SERVICES 29 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
30
WEB SERVICES 30 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
31
WEB SERVICES 31 SOAP (Simple Object Access Protocol) package ShapeListService; import java.rmi.*; public interface ShapeList extends Remote { int newShape(GraphicalObject g) throws RemoteException; int numberOfShapes()throws RemoteException; int getVersion() throws RemoteException; int getGOVersion(int i)throws RemoteException; GraphicalObject getAllState(int i) throws RemoteException; } Figure 7. Java web service interface ShapeList Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
32
WEB SERVICES 32 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.RemoteException 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
33
WEB SERVICES 33 SOAP (Simple Object Access Protocol) The class that implements the interface ShapeList is shown in Figure 8. Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
34
WEB SERVICES 34 SOAP (Simple Object Access Protocol) package ShapeListService; import java.util.Vector; public class ShapeListImpl implements ShapeList{ private Vector theList = new Vector(); private int version = 0; private Vector theVersions = new Vector(); public ShapeListImpl(){ version = 0; theVersions = new Vector(); } public int newShape(GraphicalObject g) { version++; theList.addElement(g); theVersions.addElement(new Integer(version)); return theList.size(); } public int numberOfShapes(){ return theList.size(); } public int getVersion() { return version; } public int getGOVersion(int i){ return ((Integer) theVersions.elementAt(i)).intValue(); } public GraphicalObject getAllState(int i) { return (GraphicalObject)theList.elementAt(i); } } Figure 8. Java implementation of the ShapeListserver Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
35
WEB SERVICES 35 SOAP (Simple Object Access Protocol) There is no main method, and the implementation of the ShapeList 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
36
WEB SERVICES 36 SOAP (Simple Object Access Protocol) Figure 9 shows the ShapeList client main a call through a proxy. Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
37
WEB SERVICES 37 SOAP (Simple Object Access Protocol) package staticstub; import javax.xml.rpc.Stub; public class ShapeListClient{ public static void main(String args[]){ try{ Stub stub = createProxy(); stub._setProperty (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]); aShapeList = (ShapeList) stub; System.out.println("Got stub"); int n = aShapeList.numberOfShapes(); System.out.println("Number of shapes=" + n); int v = aShapeList.getVersion(); System.out.println("Version=" + v); Vector sList = new Vector(n); for(int i=0; i<n; i++){ System.out.println("shape no =" + i); GraphicalObject g = aShapeList.getAllState(i); System.out.println("Got shape " + i); int vers = aShapeList.getGOVersion(i); sList.addElement(g); System.out.println("Version number " + vers); g.print(); } Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
38
WEB SERVICES 38 SOAP (Simple Object Access Protocol) GraphicalObject g = new GraphicalObject(shapeType,30, 40, 3300, 5500, true); System.out.println("Created graphical object"); int listLength = aShapeList.newShape(g); System.out.println("Stored shape " + shapeType); }catch(Exception e) {System.out.println("allShapes: " + e.getMessage()); } private static Stub createProxy() { return (Stub) (new MyShapeListService_Impl().getShapeListPort()); } Figure 9. Java implementation of the ShapeListclient Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4, Pearson Education 2005
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.