Introduction aux Services Web Slimane Hammoudi et Denivaldo Lopes 1 Introduction aux Services Web Plan • Introduction aux Services Web. •Le problème de l‘ Interopérabilité entre systèmes. •Les Technologies utilisées (XML, WSDL, UDDI, SOAP, ...). •La Composition des Services Web. •Les Services Web, XML-RPC, RMI et CORBA. •JWSDP (Java Web Service Developer Pack). •Un exemple avec JWSDP et dotNET 2 Introduction aux Services Web Introduction aux Services Web 3 Introduction aux Services Web Un Service Web, c’est quoi ? Un service Web est une « unité logique applicative » accessible en utilisant les protocoles standard d’Internet Une «librairie» fournissant des données et des services à d’autres applications. Un objet métier qui peut être déployé et combiné sur Internet avec une faible dépendance vis-à-vis des technologies et des protocoles. Combine les meilleurs aspects du développement à base de composants et du Web. 4 Introduction aux Services Web Notions Les Services Web fournissent une couche d'abstraction entre le client et le fournisseur d'un service. Cette couche est indépendante de la plateforme et du langage d'implémentation. Code de l'applicat ion Internet/ Intranet Service Web Fournisseur de Service API/Stub pour accéder au Service Web Client de Service Code de l'applicat ion 5 Figure 1 – Services Web Introduction aux Services Web Atoûts des services Web Réutilisabilité Interopérabilité - indépendance de: la Plate-forme (Hardware et Système d’Exploitation, e.g. Pentium avec Windows, Sparc avec Sun Solaris, PowerPc avec AIX, Pentium avec Linux, ..) l'implémentation (Java, C#, C++, ...) l'environnement de développement (J2EE, dotNET, ...) 6 Introduction aux Services Web Les Générations des applications Web 1 ° Génération - Pages Web statiques (HTML) 2 ° Génération - Des applications réelles (Pages Web dynamiques, e.g. CGI, Servlets, ASP, JSP, PHP, ...) 3 ° Génération - Les Services Web (basé sur XML) 7 Introduction aux Services Web L'évolution du Web (selon ORFALI) fonction HiperText Web Réponse simple dans la Web L’Objet Web Les Services Web Publication Électronique Formulaires Complet Client/Serveur Client/Serveur basé sur XML Serveur de fichier basé sur URL Formulaire CGI Tableau ISAPI NSAPI HTML Dynamique Scripts Cookies/Sessions ASPs CORBA plug-ins (WAI) Push WebObjects Servlets, JSP, PHP JavaBeans/Applet ActiveX Controls Interactions basées sur ORB via CORBA et DCOM Ne figure pas dans l'ouvrage de ORFALI Figure 2 – Evolution du Web XML SOAP WSDL UDDI ActiveXML Interaction 8 Introduction aux Services Web Le problème de l’ Interopérabilité entre systèmes. 9 Introduction aux Services Web Le Problème de l'Interoperabilité Applic. (AppleScript) OS X Application (C) AIX (IBM) PowerPC PowerPC G5 Application (C#) Windows XP Pentium III Internet/ Intranet Application (C++) Linux Pentium IV Application (Java) Windows 2000 Pentium IV Application (C#) Windows CE Application (C++) Sun Solaris Sun Enterprise10K (Mainframe) Application (J2EE) z/OS 10 IBM z900 (Mainframe) Figure 3 – Le Problème de l‘ Interopérabilité Introduction aux Services Web Les Services Web assurent: Interopérabilité: Différentes Applications (Client et/ou Serveur) Différents Systèmes d‘ Exploitation Différents Hardwares Distribution et Intégration des logiques métiers Faible couplage Protocoles plus adaptés au Web La plus importante innovation des Services Web est l'utilisation de XML comme EDI 11 Introduction aux Services Web Les Principales Technologies des Services Web (XML, WSDL, UDDI, SOAP, ...). 12 Introduction aux Services Web Les quatre principales technologies des Services Web eXtensible Markup Language (XML); Simple Object Access Protocol (SOAP); Web Services Description Language (WSDL); Universal Description, Discovery and Integration (UDDI) Note: HTTP, SMTP/MIME, MOM/JMS ou tout comme protocoles de transport autre protocol peuvent être utilisés 13 Introduction aux Services Web Les principaux acteurs Demandeur de services Message en Soap/HTTP Message en Soap Call Search Bind Publish Message en Soap Fournisseur de services Services Serveur UDDI WSDL des Services Figure 4 – Les principaux acteurs des Services Web Annuaire de Services Web 14 Introduction aux Services Web La description des Services Web -Comment décrire le contrat entre le client et le serveur? WSDL est un langage qui permet de décrire: - un service Web - et comment l’ invoquer 15 Introduction aux Services Web WSDL en détail WSDL permet la représentation d'un Service Web de manière plus abstraite pour la réutilisation. Structure de WSDL: <?xml version="1.0" encoding="utf-8"?> <definitions> <types>!--abstract data types</types> <message>!--message structure</message> <portType>!--Web Service Interface</portType> <binding>!--how the service is accessed</binding> <service>!--who provides the service</service> 16 </definitions> Introduction aux Services Web La publication des services Web - Comment disponibiliser les services au monde extérieur? UDDI est un annuaire qui permet: - l’enregistrement des services. - la découverte des informations sur les services. 17 Introduction aux Services Web UDDI en détail Une structure de données basée sur XML pour faciliter la découverte des services (XML Schema). • • Similaire à la figure (ci-dessous). UDDI Page blanche (pour trouver un service par contact, nom et adresse) Page Jaune (pour trouver un service par sujet basé sur taxonomies standards) Page vert (pour trouver un service par caractéristiques techniques) Figure 5 – L'annuaire UDDI 18 Introduction aux Services Web UDDI en détail businessEntity: informations sur la partie qui publie les informations sur le service tModel: Déscription des spécifications pour services ou taxonomies. businessService: informations déscriptives sur une famille particuliere de services BindingTemplates ont réferences pour tModels. Ces réferences désignent les spécifications des interfaces pour un service. bindingTemplate: information technique sur le point d'entrer et spécification de constructions Figure 6 – Structure de donnée d'un enregistrement de UDDI 19 Introduction aux Services Web Les messages Comment appeler et obtenir le résultat d'un service Web? SOAP est un protocole de transmission de messages: il est particulièrement utile pour exécuter des dialogues requête-réponse RPC (Remote Procedure Call) 20 Introduction aux Services Web SOAP (Simple Object Access Protocol) SOAP est un protocole léger pour accomplir la transmission des informations structurées dans une environnement distribué et décentralisé [W3C]. Le protocole SOAP définit: Une enveloppe; une mise en œuvre sur HTTP (HTTP Extension Framework); Un ensemble de règles de codages; Un fonctionnement en modèle client / serveur (RPC) 21 Introduction aux Services Web La Structure d’un Message SOAP SOAP Message Le message SOAP HTTP Headers Entête Standard HTTP et entête SOAP HTTP Envelope SOAP Envelope SOAP Header Headers SOAP Body Method Call and Data Figure 7 – Structure d'un message SOAP Entête Entête individulle Corps du message SOAP Appel de méthode et description de données 22 Résumé d’un Services Web 1 : Le fournisseur de service Web publie ses Services Web 2 : Le client recherche un service WEB avec les characteristics X, Z et Y UDDI (XML) Annuaire UDDI UDDI (XML) 3 : L’annuaire a trouvé un service avec les caractéristiques X, Z et Y, il envoie l’information du serveur qui le héberge 4 : Quel est le contrat du service Web que tu proposes? 5 : Voici mon format d’appel WSDL (XML) Serveur Client 6 : J’appel ton service Web SOAP (XML) SOAP (XML) 7 : Voici le résultat du service Web Introduction aux Services Web La Composition de Services Web Introduction aux Services Web Les entreprises et le e-business Internet Serveurs Web Serveurs Clients Figure 8 – Les entreprises, les e-business et les clients 25 Introduction aux Services Web Composition de Services Web Agence de tourisme Serveur Web Internet Serveurs Web Clients Serveurs Figure 8 – L'angence de tourisme comme “composition de services Web”26 Introduction aux Services Web Composition de Services Web avec Workflow XLANG (Web Services for Business Process Design) le (http://www.ebpml.org/xlang.html) WSFL (Web Services Flow Language) (http://www-3.ibm.com/software/solutions/webservices/pdf/WSFL.pdf) BPML (Business Process Modeling Language) (http://www.bpmi.org/bpml.esp) WSCI (Web Services Choreography Interface) (http://wwws.sun.com/software/xml/developers/wsci) Introduction aux Services Web Un comparatif entre les Services Web, XML-RPC, RMI et CORBA Introduction aux Services Web Les Services Web et XML-RPC La Pile de Service Web La Pile de XML-RPC WSDL UDDI SOAP Message XML HTTP TCP/IP ------XML-RPC Protocol XML HTTP TCP/IP 29 Introduction aux Services Web Les Services Web et Java RMI La Pile de Service Web La Pile de Java RMI WSDL UDDI SOAP Message XML HTTP TCP/IP ------- (+/- rmiregistry) JRMP Serialization rmi TCP/IP 30 Introduction aux Services Web Les Services Web et CORBA La Pile de Service Web La Pile de CORBA WSDL UDDI SOAP Message XML HTTP TCP/IP IDL CORBA Services CORBA Stubs/Skeletons CDR binary representation GIOP/IIOP TCP/IP 31 Introduction aux Services Web Les Outils de Développements des Services Web 32 Introduction aux Services Web Les Outils de développements des Services Web - Java Web Service Developer Pack (JWSDP) -> Sun (Java) -> JVM http://java.sun.com/webservices/index.html - .NET -> Microsoft (C#, VB.NET, …) -> Windows http://msdn.microsoft.com/webservices - Axis -> Apache (Java et C++) -> JVM http://ws.apache.org/axis/cpp/index.html - gSOAP -> Robert van Engelen (C/C++) Win, Linux, Unix (SunSolaris, SGI IRIX), Mac OS X http://www.cs.fsu.edu/~engelen/soap.html - - IBM WebSphere SDK for Web Services -> IBM (Java) ->JVM http://www-106.ibm.com/developerworks/webservices/wsdk 33 Introduction aux Services Web Un exemple avec JWSDP et .NET 34 Introduction aux Services Web Exemple de Services Web – Hello World! (modélisation) Service 1 Message: String HelloWorld(i_am: String): String Consumer I_am : String Invoke_service() : void Figure 8 – Diagramme de Classe Consumer Service 1 1: HelloWorld(param:String) 2: return (msg:String) 35 Figure 9 – Diagramme de séquence Introduction aux Services Web Hello World en C# (Implementation) using System; using System.Web; using System.Web.Services; // other using namespace WebService_demo { public class Service1 : System.Web.Services.WebService { public Service1() { message= "I am C# (.NET) in Windows! "; InitializeComponent(); } private IContainer components = null; private void InitializeComponent(){ } protected override void Dispose( bool disposing ) { if(disposing && components != null) { base.Dispose(disposing); } components.Dispose(); [WebMethod] public string HelloWorld(string i_am) { return i_am+message; } public string message; } } 36 Introduction aux Services Web WSDL en détail WSDL permet la représentation du service “Hello World” de manière plus abstraite pour permettre la réutilisation. Structure de WSDL: <?xml version="1.0" encoding="utf-8"?> <definitions> <types>!--abstract data types</types> <message>!--message structure</message> <portType>!--Web Service Interface</portType> <binding>!--how the service is accessed</binding> <service>!--who provides the service</service>37 </definitions> Introduction aux Services Web WSDL de Hello World <definitions> et <types> <?xml version="1.0" encoding="utf-8"?> <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://tempuri.org/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://tempuri.org/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"> <s:element name="HelloWorld"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="i_am" type="s:string" /> </s:sequence> </s:complexType> </s:element> <s:element name="HelloWorldResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> </s:sequence> </s:complexType> </s:element> <s:element name="string" nillable="true" type="s:string" /> </s:schema> </t > 38 Introduction aux Services Web WSDL de Hello World <message> <message name="HelloWorldSoapIn"> <part name="parameters" element="s0:HelloWorld" /> </message> <message name="HelloWorldSoapOut"> <part name="parameters" element="s0:HelloWorldResponse" /> </message> <message name="HelloWorldHttpGetIn"> <part name="i_am" type="s:string" /> </message> <message name="HelloWorldHttpGetOut"> <part name="Body" element="s0:string" /> </message> <message name="HelloWorldHttpPostIn"> <part name="i_am" type="s:string" /> </message> <message name="HelloWorldHttpPostOut"> <part name="Body" element="s0:string" /> </message> 39 Introduction aux Services Web WSDL de Hello World <portType> <portType name="Service1Soap"> <operation name="HelloWorld"> <input message="s0:HelloWorldSoapIn" /> <output message="s0:HelloWorldSoapOut" /> </operation> </portType> <portType name="Service1HttpGet"> <operation name="HelloWorld"> <input message="s0:HelloWorldHttpGetIn" /> <output message="s0:HelloWorldHttpGetOut" /> </operation> </portType> <portType name="Service1HttpPost"> <operation name="HelloWorld"> <input message="s0:HelloWorldHttpPostIn" /> <output message="s0:HelloWorldHttpPostOut" /> </operation> </portType> 40 Introduction aux Services Web WSDL de Hello World <binding> <binding name="Service1Soap" type="s0:Service1Soap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> <operation name="HelloWorld"> <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <binding name="Service1HttpGet" type="s0:Service1HttpGet"> <http:binding verb="GET" /> <operation name="HelloWorld"> <http:operation location="/HelloWorld" /> <input> <http:urlEncoded /> </input> <output> <mime:mimeXml part="Body" /> / 41 Introduction aux Services Web WSDL de Hello World <binding> <binding name="Service1HttpPost" type="s0:Service1HttpPost"> <http:binding verb="POST" /> <operation name="HelloWorld"> <http:operation location="/HelloWorld" /> <input> <mime:content type="application/x-www-form-urlencoded" /> </input> <output> <mime:mimeXml part="Body" /> </output> </operation> </binding> 42 Introduction aux Services Web WSDL de Hello World <service> <service name="Service1"> <port name="Service1Soap" binding="s0:Service1Soap"> <soap:address location="http://pc-lopes:1050/WebService_demo/Service1.asmx" /> </port> <port name="Service1HttpGet" binding="s0:Service1HttpGet"> <http:address location="http://pc-lopes:1050/WebService_demo/Service1.asmx" /> </port> <port name="Service1HttpPost" binding="s0:Service1HttpPost"> <http:address location="http://pc-lopes:1050/WebService_demo/Service1.asmx" /> </port> </service> </definitions> 43 Introduction aux Services Web UDDI en détail Une structure de donné basée sur XML pour faciliter la découverte de services (XML Schema). • • Similaire à la figure 10. UDDI Page blanche (pour trouver un service par contact, nom et adresse) Page Jaune (pour trouver un service par sujet basé sur taxonomies standards) Page vert (pour trouver un service par caractéristiques techniques) Figure 10 – L'annuaire UDDI 44 Introduction aux Services Web UDDI en détail Access URI: http://localhost:8080/hello-jaxrpc/hello?WSDL Figure 11 – Example d'un enregistrement sur UDDI avec JAXR Registry Browser 45 Introduction aux Services Web Client de Hello World en Java (JAX-RPC) package consumer; import service_stub.*; import javax.xml.rpc.Stub; public class Client_hello{ public static void main(String[] args) { System.out.println("Invoking the Web Service – Hello World..." ); invoque_service(); } private static Stub createProxy() { return (Stub)(new Service1_Impl().getService1Soap()); } private static void invoque_service() { try { Stub stub = createProxy(); Service1Soap service_helloworld = (Service1Soap)stub; System.out.println( service_helloworld.helloWorld( "Hello World! I am Java (JWSDP) in Linux and are you?" ) } catch (Exception ex) { ex.printStackTrace(); } } } 46 Introduction aux Services Web Exécution de Hello World Services Service 1 Consumer I_am : String Invoke_service() : void Message: String HelloWorld(i_am: String): String Fournisseur de services Client Demandeur de services Appel en Soap/HTTP JWSDP Réponse en Soap/HTTP Hello World! I am Java (JWSDP) in Linux and are you? Hello World! I am Java (JWSDP) in Linux and are you? I am C# (.NET) in Windows! Figure 12 – Exécution du Service “Hello World” avec .NET et client avec JWSDP 47 Introduction aux Services Web La Structure du message SOAP SOAP Message HTTP Headers SOAP Envelope SOAP Header Headers SOAP Body Method Call and Data Figure 13 – Structure d'un message SOAP Le message SOAP Entête Standard HTTP et entête SOAP HTTP Enveloppe Entête Entêtes individulles Corps de la message SOAP Appel de méthode et description de données 48 Introduction aux Services Web Le message en SOAP (Appel à distance) POST /WebService_demo/Service1.asmx HTTP/1.1 Content-Type: text/xml; charset="utf-8" Content-Length: 520 SOAPAction: "http://tempuri.org/HelloWorld" User-Agent: Java/1.4.1 Host: 192.168.10.56:1050 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive <?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://tempuri.org/" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <env:Body> <ns0:HelloWorld env:encodingStyle=""> <ns0:i_am>Hello World! I am Java (JWSDP) in Linux and are you?</ns0:i_am> </ns0:HelloWorld> </env:Body> 49 </env:Envelope> Introduction aux Services Web Le message en SOAP (Réponse) HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://tempuri.org/"> Hello World! I am Java (JWSDP) in Linux and who are you? I am C# (.NET) in Windows! </string> 50 Introduction aux Services Web JWSDP (Java Web Services Developer Pack) 51 Introduction aux Services Web JWSDP (Java Web Services Developer Pack) Java API for XML Binding (JAXB) Java API for XML Messaging (JAXM) Soap with Attachments API for Java (SAAJ) Java API for XML Processing (JAXP) Java API for XML Registries (JAXR) Java API for XML-based RPC (JAX-RPC) JavaServer PagesTM Standard Tag Library (JSTL) Tomcat (Java servlet and JavaServer Pages container) Administration Tool Web Application Manager Ant build tool Registry Server 52 Introduction aux Services Web Tomcat Web Server Container pour: Servlets, Java Server Pages, Web Services, Enterprise Java Beans, ... 53 Introduction aux Services Web Tomcat 54 Figure 14 – Serveur Tomcat Introduction aux Services Web Tomcat 55 Figure 15 – Serveur Tomcat (Internal Services) Introduction aux Services Web Tomcat 56 Figure 16 – Serveur Tomcat (Java Web Services Developer Pack) Introduction aux Services Web Tomcat 57 Figure 17 – Serveur Tomcat (Resources et User Definition) Introduction aux Services Web Web Applications et l'Architecture 3-Tier Client Client Tier (a.k.a Front End) (Thin Client) It can be a pocket-PC, etc Web Browser Workstation PC Enterprise Tier (a.k.a Middle Tier) Internet/Intranet HTML Pages dynamically generated Business Logic Servlets, ASP.NET, JavaServerPages, PHP, etc Web Servers (Apache Tomcat, IIS Microsoft, etc) Servers DataBase Tier (a.k.a Back End) Oracle MySQL Other DBs Mainframe Pentium Linux Orther servers Figure 18 – L'Architecutre Three-Tier – thin client 58 Introduction aux Services Web Web Applications et l'Architecture 4-Tier User Tier (a.k.a Client End) Client User Presentation Workstation PC Workspace Tier (a.k.a Interaction Tier) Enterprise Tier (a.k.a Business Tier) Resource Tier (a.k.a Integration Tier) User Interaction Logic Servers Business Logic Servers Resource Adapters Application Adapters Fi Oracle DB Legacy System Mainframe DB Mainframe 19 L'A hit t F 59 Ti Introduction aux Services Web Un autre exemple de Services Web Un convertiseur d'argent Figure 20 – Le cas d'utilisation du Service Web Composite Introduction aux Services Web Un convertiseur d'argent Figure 21 – Le diagramme de classe Introduction aux Services Web L'Architecture Client Client Tier Mozzila Windows XP - Intel Enterprise Tier HTML dynamically generated with Servlet JWSDP- Tomcat Linux - Intel DataBase Tier Internet/Intranet It uses JDBC to access the DB Oracle 8i Intranet Oracle Linux - Intel Figure 22 – L'architecture 3-tier thin client du convertiseur d'argent 62 Introduction aux Services Web Exemple de l'exécution du Service Web Figure 23 – Le Service Web “Universal Converter” 63 Introduction aux Services Web Conclusion: - Les Points forts des Services WEB XML comme Electronique Data Interchange (EDI) Le Web comme l’environnent de développement Il utilise les standards de W3C et OASIS Interopérabilité La modularité et l’extensibilité des aspects: choix du protocole de communication synchrone/asynchrone 64 Introduction aux Services Web Bibliographie Extensible Markup Language (XML), W3C (http://www.w3.org/XML/) Simple Object Access Protocol (SOAP) 1.1, W3C Submission, May, 2001. (http://www.w3.org/TR/SOAP/) UDDI Project, UDDI Technical White Paper, September 2000. Web Services Description Language (WSDL) 1.1, W3C Note, March 2001. (http://www.w3.org/TR/wsdl) Common Object Request Broker Architecture (CORBA), OMG (http://www.omg.org) dotNET, Microsoft (http://www.microsoft.com/net) (http://www.dotnet-fr.org) Java Web Service Developer Pack 1.1 (JWSDP), Sun Microsystems (http://java.sun.com/webservices/archive.html) -> JWSDP version 1.1 (http://java.sun.com/webservices) -> JWSDP last version 65 Introduction aux Services Web Bibliographie XML-RPC Protocol, (http://www.xmlrpc.com) Java RMI, Sun Microsystems (http://java.sun.com/products/jdk/rmi) JDBC, Sun Microsystems (http://java.sun.com/products/jdbc) HyperTest Markup Language (HTML), W3C (http://www.w3.org/MarkUp) Servlet, Sun Microsystems (http://java.sun.com/products/servlet) SQL, (http://www.sql.org) Oracle 8i, Oracle (http://www.oracle.com) 66 Introduction aux Services Web Bibliographie Alex Ferrata and Matthew MacDonald, Programming .NET Web Services, O'Reilly, September 2002. ISBN: 0-596-00250-5 Simon St. Laurent, Joe Johnston, et al., Programming Web Services with XML-RPC, O'Reilly, June 2001. ISBN: 0-596-00119-3 David A. Chappell and Tyler Jewell, Java Web Services, O'Reilly, March 2002. ISBN: 0596-00269-6 Ethan Cerami, Web Services Essentials – Distributed Applications with XML-RPC, SOAP, UDDI and WSDL, O'Reilly, February 2002. ISBN: 0-596-00224-6 James Snell, Doug Tidwell and Pavel Kulchenko, Programming Web Services with SOAP – Building Distributed Applications, O'Reilly, January 2002. ISBN: 0-596-00095-2 George Reese, Database Programming with JDBC and Java, Second Edition, 2nd Edition 2000, O'Reilly, 2000. ISBN: 1-56592-616-1 67 Introduction aux Services Web MERCI de votre Attention! 68