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 Topics Introduccion Web Services 2 Introduction Los servicios web son una manera de interacción entre C/S mas general que invocación de programas invocadas por el browser. Los clientes acceden al servicio con el mecanismo de pregunta/respuesta (request/response) donde estas están formateadas como XML y habitualmente transferidas utilizando HTTP. 3 1
Introduction Sirven para acceder servicios que se encuentran en servidores ajenos y por eso deberían de estar seguros. Transport Layer Security TLS no proporciona la seguridad adecuada. XML security sirve mas. B2B services. 4 Introduction Figure 1. Web services infrastructure and components 5 Introduction Marshalling de los mensajes en XML. Se identifica como URI (extension de URL) Se utiliza de modo habitual. SOAP se puede utilizar con HTTP/SMTP etc. La descripcion de servicio proporciona la definicion de la interfaz. Web Service Description Language (WSDL). 6 2
Web Services Una interfaz de SW consiste de un conjunto de operaciones que el cliente puede utilizar vía Internet. Pueden estar proporcionados de diferentes formas (programas, objetos remotos, bases de datos). Se puede manejar en paginas WEB o puede estar totalmente separado de paginas WEB. 7 Web Services Ejemplos: ebay. Amazon, Yahoo, Google. Amazon.com info de productos, compras. 8 Web Services Combinacion de SW. 9 3
Web Services Objetivo principal hacer acceso mas fácil al servicio. Nivel mas bajo R/Wen SOAP, utilizando XML. 10 SOAP permite en una arquitectura C/S al C y al S una interacción asíncrona (pero también síncrona y de eventos). Esta definida como subnorma de XML (esquema) para representar el los mensajes contenido de pregunta/respuesta. Inicialmente SOAP esta basado a HTTP, pero se puede utilizar con varios TP: SMTP, TCP o UDP. Coupling loose/no tanto. 11 SOAP is an XML based protocol for accessing Web Services. SOAP is a communication protocol SOAP is for communication between applications SOAP is a format for sending messages SOAP communicates via Internet 4
SOAP is platform independent SOAP is language independent SOAP is based on XML SOAP is simple and extensible SOAP allows you to get around firewalls SOAP is a W3C recommendation SOAP especifica: Como XML se utiliza en de representar contenido de mensajes individuales. Como combinan la pregunta (request) y la respuesta (reply). Como el recipiente tiene que interpretar los elementos de XML. Como utilizar HTTP y SMTP para comunicar msg. de SOAP. 15 5
Mensaje del sobre de SOAP 16 Headers establece el contexto, pero también log y audit. El cuerpo (body) esta especifico para cada servicio WEB. Definición formal en SOAP XML namespace. 17 <SOAP-ENV:Envelope xmlns:soap- ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/xmlschema-instance" xmlns:xsd="http://www.w3.org/1999/xmlschema"> <SOAP-ENV:Body> <ns1:dogooglesearch xmlns:ns1="urn:googlesearch" SOAP- ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <key xsi:type="xsd:string">00000000000000000000000000000000</key> <q xsi:type="xsd:string">lo que vamos a buscar google lo sabra</q> <start xsi:type="xsd:int">0</start> <maxresults xsi:type="xsd:int">10</maxresults> <filter xsi:type="xsd:boolean">true</filter> <restrict xsi:type="xsd:string"></restrict> <safesearch xsi:type="xsd:boolean">false</safesearch> <lr xsi:type="xsd:string"></lr> <ie xsi:type="xsd:string">latin1</ie> <oe xsi:type="xsd:string">latin1</oe> </ns1:dogooglesearch> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 6
Ejemplo de request 19 <?xml version='1.0' encoding='utf-8'?> <SOAP-ENV:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/xmlschema-instance" xmlns:xsd="http://www.w3.org/1999/xmlschema"> <SOAP-ENV:Body> <ns1:dogooglesearchresponse xmlns:ns1="urn:googlesearch" SOAPENV: encodingstyle="http://schemas.xmlsoap.org/soap/encoding/"> <return xsi:type="ns1:googlesearchresult"> <documentfiltering xsi:type="xsd:boolean">false</documentfiltering> <estimatedtotalresultscount xsi:type="xsd:int">3</estimatedtotalresultscount> <directorycategories xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:array" ns2:arraytype="ns1:directorycategory[0]"></directorycategories> <searchtime xsi:type="xsd:double">0.194871</searchtime> <resultelements xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:array" ns3:arraytype="ns1:resultelement[3]"> <item xsi:type="ns1:resultelement"> <cachedsize xsi:type="xsd:string">12k</cachedsize> <hostname xsi:type="xsd:string"></hostname> <snippet xsi:type="xsd:string"> <b>...</b> on a simple dialog (via <b>teletype</b>) with... vintage 1970, and to <b>...</b></snippet> <directorycategory xsi:type="ns1:directorycategory"> <specialencoding xsi:type="xsd:string"></specialencoding> <fullviewablename xsi:type="xsd:string"></fullviewablename> </directorycategory>... Ejemplo reply 21 7
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. 22 Figure 6 illustrates how the HTTP POST method is used to transmit a SOAP message. 23 Figure 6. Use of HTTP POST Request in SOAP client-server communication 24 8
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. 25 END (Java language) 27 9
Figure 7 shows a web service interface. 28 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 29 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. 30 10
The class that implements the interface ShapeList is shown in Figure 8. 31 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 32 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. 33 11
Figure 9 shows the ShapeList client main a call through a proxy. 34 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(); 35 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 36 12