10.07.2015 Views

Introduzione ai Web Services - Moreno Marzolla

Introduzione ai Web Services - Moreno Marzolla

Introduzione ai Web Services - Moreno Marzolla

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Web</strong> Service“A <strong>Web</strong> service is a software system designed tosupport interoperable machine-to-machineinteraction over a network. It has an interface describedin a machine-processable format (specifically WSDL).Other systems interact with the <strong>Web</strong> service in a mannerprescribed by its description using SOAP-messages,typically conveyed using HTTP with an XML serializationin conjunction with other <strong>Web</strong>-related standards.”http://www.w3.org/TR/2004/NOTE-ws-gloss-20040211/<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 4


Tecnologie dei <strong>Web</strong> <strong>Services</strong>●L’infrastruttura dei WS si basa su diverse tecnologieXML per il trasporto, lo scambio e la trasformazionedei dati tra programmi e applicazioni. In particolare:XML (Extensible Markup Language), fornisce un linguaggio perdefinire i dati e processare i dati.WSDL (<strong>Web</strong> Service Description Language), una notazioneXML per definire le interfacce dei WS.SOAP (Simple Object Access Protocol), una notazione XML chefornisce un meccanismo di packaging dei messaggiUDDI (Universal Description, Discovery and Integration), unmeccanismo per registrare, categorizzare e rintracciare leinterfacce WS.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 5


Stack dei WSWS-BPELProcessiUDDIDiscoveryWSDLDescrizioneSOAPXMLMessaggiHTTP, FTP, SMTPTrasporto<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 6


SOAP●Il Simple Object Access Protocol (SOAP):Definisce un meccanismo per il trasporto dei dati da unpunto all’altro della rete.Consente al mittente e al destinatario di un documento XMLdi disporre di un protocollo comune.Consente la spedizione di messaggi XML su HTTP e larelativa ricezione di una risposta.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 7


SOAP—Formato dei messaggi●Un messaggio SOAP somiglia ad una lettera. Sipuò quindi schematizzare un documento SOAPcome una lettera composta da:Una busta (Envelope);Informazioni varie per la spedizione del messaggio (Header);Un documento da spedire (Body).SOAP EnvelopeSOAP BodySOAP Header(questa componenteè opzionale)<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 8


SOAP—Formato dei messaggi●Un messaggio SOAP è un documento XMLconsistente in:Un elemento SOAP Envelope (obbligatorio) che rappresentala radice del documento XML; tale elemento DEVE esserepresente nel documento, PUO’ contenere un Header, DEVEcontenere un BODY.Un elemento SOAP Header (opzionale) contenenteinformazioni aggiuntive per la comprensione e la spedizionedel messaggio.Un elemento SOAP Body (obbligatorio) contenente leinformazioni che si intendono far giungere al destinatario. Alsuo interno viene inoltre definito l’elemento Fault usato per lagestione degli errori; viene come primo figlio dopo Header.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 9


SOAP—Formato dei messaggiSOAP EnvelopeSOAP HeaderParti dell'HeaderSOAP BodyDati da spedireSOAP Faultattributi del messaggiomessaggiogestione errori<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 10


Esempiouuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d2001-11-29T13:20:00.000-05:00Åke Jógvan ØyvindNew YorkLos Angeles2001-12-14late afternoon<strong>ai</strong>sleLos AngelesNew York2001-12-20mid-morningnone<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 11


EsempioSOAP Envelopeuuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d SOAP Header2001-11-29T13:20:00.000-05:00Åke Jógvan ØyvindHeader BlockNew YorkLos Angeles2001-12-14late afternoon<strong>ai</strong>sleLos AngelesNew York2001-12-20mid-morningpassengerSOAP BodyBody sub-elementitineraryBody sub-elementlodgingnone<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 12


SOAP Envelope●●L’elemento Envelope identifica l’inizio e la finedel messaggio, in maniera tale che il riceventesappia quando l’intero messaggio è stato ricevuto.Si risolve in questo modo il problema di saperequando la ricezione è completata e si può iniziarea processare il messaggio.Agisce come meccanismo di packaging.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 13


SOAP Header●●Le informazioni contenute nell’header:possono essere utilizzate da intermediari SOAP identificatida URI in un qualunque punto del cammino seguito dalmessaggio.non devono essere indirizzate necessariamente aldestinatario finale.L’attributo mustUnderstand è usato per indicarese una voce dell’Header debba essere elaboratadal destinatario o meno.Se un elemento dell’Header possiede questo attributo convalore “true”, il destinatario deve elaborarlo correttamenteoppure restituire un errore<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 14


SOAP Body●●Il Body di un messaggio SOAP può essere vistocome il documento vero e proprio che si vuolespedire: questa parte contiene i dati che siintendono mandare al destinatario.L’elemento fault del body trasporta informazioniriguardanti gli errori occorsi durante la spedizionedel messaggio.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 15


SOAP Body. Elemento fault


SOAP con HTTP●●●Benché SOAP possa utilizzare diversi protocollidi trasporto, HTTP è quello più comunementeusato.Le richieste HTTP consistono in un comandoHTTP, come POST o GET, seguito dall’URLrichiesto e dalla versione del protocollo (es.HTTP 1.1).Le risposte seguono la semantica di HTTP perfornire il codice dello stato della risposta;Ad esempio, uno status code del tipo 2xx indica che larichiesta è stata ricevuta, capita, accettata, ecc.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 17


SOAP con HTTP●●Esistono due modelli per lo scambio di messaggiSOAP via HTTP:il modello “SOAP request-response” in cui il metodo POSTviene utilizzato per portare i messaggi SOAP nel Body dellerichieste/risposte http;il modello “SOAP response” in cui nelle richieste http vieneusato il metodo GET per ottenere il messaggio SOAP edinserirlo nel Body della risposta.Utilizzando SOAP con HTTP si devono ricordaredi settare l’header Content-Type comeapplication/SOAP+xml<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 18


Richiesta HTTP GETSOAP con HTTP GETGET /travel.example.org/reservations?code=F3T HTTP/1.1Host: travelcompany.example.orgAccept: text/html;q=0.5, application/soap+xmlRisposta HTTP GETHTTP/1.1 200 OKContent-Type: application/soap+xml; charset="utf-8“Content-Length: 200……<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 19


Richiesta HTTP POSTSOAP con HTTP POSTPOST /Reservations HTTP/1.1Host: travelcompany.example.orgContent-Type: application/soap+xml; charset="utf-8“Content-Length: 230 ... ... Risposta HTTP POST simile al caso della GET<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 20


SOAP via m<strong>ai</strong>l—RichiestaFrom: a.oyvind@mycompany.example.comTo: reservations@travelcompany.example.orgSubject: Travel to LADate: Thu, 29 Nov 2001 13:20:00 ESTMessage-Id: Content-Type: application/soap+xmluuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d2001-11-29T13:20:00.000-05:00Åke Jógvan ØyvindNew YorkLos Angeles2001-12-14late afternoon<strong>ai</strong>sleLos AngelesNew York2001-12-20mid morningnone<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 21


SOAP via m<strong>ai</strong>l—RispostaFrom: reservations@travelcompany.example.orgTo: a.oyvind@mycompany.example.comSubject: Which NY <strong>ai</strong>rport?Date: Thu, 29 Nov 2001 13:35:11 ESTMessage-Id: In-reply-to:Content-Type: application/soap+xmluuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d2001-11-29T13:35:00.000-05:00Åke Jógvan Øyvind......<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 22


WSDL●Il <strong>Web</strong> Service Description Language (WSDL) èuna notazione XML con cui descrivere leinterfacce dei <strong>Web</strong> <strong>Services</strong>.un documento WSDL fornisce ad un programmatore unadescrizione di come può essere instaurata unacomunicazione con un determinato servizio; un sistemaautomatico potrebbe utilizzare questa descrizione perinvocare dinamicamente un servizio <strong>Web</strong>.generare automaticamente, a partire da una descrizioneWSDL, il servizio stesso o il client per inoltrare delle richiesteal servizio descritto<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 23


● WSDL fornisce :●WSDLun meccanismo comune per rappresentare le operazionisupportare d<strong>ai</strong> WS.la definizione dei tipi di dato da utilizzare nei messaggi.il meccanismo il binding dei messaggi con i protocolli ditrasporto da adottare.WSDL è progettato per poter essere utilizzato sianella modalità procedure-oriented (RPC) chedocument-oriented.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 24


WSDL<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 25


Elementi principali di WSDL●Un documento WSDL utilizza i seguenti elementiper descrivere un servizio:L'elemento types descrive i tipi di messaggi che il servizioinvia e riceveL'elemento interface descrive le funzionalità astrattefornite dal WSL'elemento binding descrive come accedere al servizioL'elemento service descrive dove è possibile accedere alservizio<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 26


WSDL by example●Consideriamo un ipotetico hotel, che voglia fornireuna interfaccia WS per implementare le dueseguenti funzionalitàCheckAv<strong>ai</strong>lability: controlla la disponibilità di unacamera. Ovvorre specificare: data di arrivo (check-in date),data di partenza (check-out date), tipo di stanza. Questometodo ritorna un numero reale (il costo della stanza algiorno). se c'è una stanza disponibile, zero altrimenti.MakeReservation: Riceve in input anche cognome, nomee numero di carta di credito.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 27


WSDL by example<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 28


●●Mediante il tag è possibile definire i tipidi dato utilizzati negli scambi di messaggiWSDL utilizza in genere XML Schema per ladichiarazione dei tipi<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 29


WSDL passo passo / types<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 30


●A WSDL 2.0 interface defines the abstractinterface of a <strong>Web</strong> service as a set of abstractoperations, each operation representing a simpleinteraction between the client and the service.Each operation specifies the types of messages that theservice can send or receive as part of that operation.Each operation also specifies a message exchange patternthat indicates the sequence in which the associatedmessages are to be transmitted between the parties.For example, the in-out pattern indicates that if the clientsends a message in to the service, the service will eithersend a reply message back out to the client (in the normalcase) or it will send a fault message back to the client (in thecase of an error).<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 31


WSDL passo passo / interface<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 32


●Although we have specified what abstractmessages can be exchanged, we have not yetspecified how those messages can beexchanged. This is the purpose of a binding.A binding specifies concrete message format andtransmission protocol det<strong>ai</strong>ls for an interface, and mustsupply such det<strong>ai</strong>ls for every operation and fault in theinterface.In the general case, binding det<strong>ai</strong>ls for each operation andfault are specified using operation and fault elements insidea binding element.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 33


WSDL passo passo / binding<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 34


●●●Now that our binding has specified how messageswill be transmitted, we are ready to specify wherethe service can be accessedA WSDL 2.0 service specifies a single interfacethat the service will support, and a list of endpointlocations where that service can be accessed.A service is only permitted to have one interface.<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 35


●●Documentation should expl<strong>ai</strong>n the purpose anduse of the service, the meanings of all messages,constr<strong>ai</strong>nts on their use, and the sequence inwhich operations should be invoked.The documentation element allows the WSDL2.0 author to include some human-readabledocumentation inside a WSDL 2.0 documentThis document describes the GreatH <strong>Web</strong> service. Additionalapplication-level requirements for use of this service --beyond what WSDL 2.0 is able to describe -- are av<strong>ai</strong>lableat http://greath.example.com/2004/reservation-documentation.html<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 36


REST●●REST: REpresentational State TransferUtilizza le caratteristiche e i protocolli del World Wide <strong>Web</strong>come modelli architetturalihttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmNon è un protocolloE' possibile costruire servizi RESTful mediante HTTP oppureSOAP<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 37


REST: Principi fondamentali●Ogni risorsa è rappresentata da un URIUn job Grid in esecuzione sull'host cream-01.pd.infn.ithttp://cream-01.pd.infn.it/activities/CREAM01324Lo stato del job di cui soprahttp://cream-01.pd.infn.it/activities/CREAM01324/statusLa descrizione del job di cui soprahttp://cream-01.pd.infn.it/activities/CREAM01324/submitted<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 38


REST: Principi fondamentali●E' possibile avere rappresentazioni multiple dellastessa risorsaGET /activities/CREAM01324/submitted HTTP/1.1Host: cream-01.pd.infn.itAccept: text/xmlHTTP/1.1 200 OKContent-Type: text/xml...Rappresentazione JSDL del job...GET /activities/CREAM01324/submitted HTTP/1.1Host: cream-01.pd.infn.itAccept: text/pl<strong>ai</strong>nHTTP/1.1 200 OKContent-Type: text/pl<strong>ai</strong>n...Rappresentazione Classad(JDL) del job...<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 39


REST: Principi fondamentali●Interfaccia uniformePOST /activities/CREAM01324/status HTTP/1.1Host: cream-01.pd.infn.itContent-length: XXXCotnent-type: text/pl<strong>ai</strong>nCANCELLED<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 40


Riferimenti●<strong>Web</strong> <strong>Services</strong> Glossary, http://www.w3.org/TR/ws-gloss/●<strong>Web</strong> <strong>Services</strong> Description Working Group,http://www.w3.org/2002/ws/desc/●SOAP Version 1.2 Part 0: Primer (Second Edition), W3C Recommendation27 April 2007, http://www.w3.org/TR/2007/REC-soap12-part0-20070427/●<strong>Web</strong> <strong>Services</strong> Description Language (WSDL) Version 2.0 Part 0: Primer,W3C Recommendation 26 June 2007,http://www.w3.org/TR/2007/REC-wsdl20-primer-20070626/●S. Andreozzi, M. <strong>Marzolla</strong>, A RESTful Approach to the OGSA BasicExecution Service Specification, INFN Technical Note INFN/TC_08/4,september 22, 2008http://www.dsi.unive.it/~marzolla/papers/infn_tc_08_4_besrest.pdf<strong>Moreno</strong> <strong>Marzolla</strong> <strong>Introduzione</strong> <strong>ai</strong> <strong>Web</strong> <strong>Services</strong> 41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!