31
Introduction aux Services Web 1 Département Sciences Informatiques Jean-Yves Tigli – [email protected] http://www.tigli.fr SI 3 ème année

Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Introduction aux Services Web

1

Département Sciences Informatiques

Jean-Yves Tigli – [email protected]

http://www.tigli.fr

SI 3ème année

Page 2: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Le web de H2M à M2M

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr2

Page 3: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Principes du Web Statique H2M

Serveurs,

Pages

Liens hypertexte

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr3

NET

TCP IP

Page 4: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Client / Serveur Particuliers

Page Web:

– Pointés par une URL

– La plupart des pages WEB se composent de:

Une page HTML de base,

Différentes références à des « objets »

L’agent utilisateur (client) pour le Web s’appel un

“browser” (butineur en français)

– Microsoft Internet Explorer, Mozilla FireFox, Opera, Safari,

Google Chrome, …

Un serveur pour le Web s’appelle un serveur Web :

– Apache, Microsoft Internet Information Server (IIS), …

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr4

Page 5: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Principes du Web Dynamique

H2M Serveurs,

Pages

Liens hypertexte

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr

NET

5

TCP IP

Page 6: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

LE WEB M2M

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr6

Page 7: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Principes du Web M2M

Serveurs,

Pages

Liens hypertexte

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr

NET

7

TCP IP

Page 8: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Principes du Web M2M

Serveurs,

Messages :

– Requête : entête HTTP, commande

HTTP et URL et paramètres

– Réponse : entête et corps HTTP

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr

NETCLIENTSERVEUR

8

TCP IP

Page 9: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Web M2M : Des CGI Bin aux

Services Web

Gérer l’interopérabilité avec HTTP (le WEB)

Choisir un protocole de communication

client/serveur over HTTP

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr9

ApplicationCliente

Client

HTTP

Serveur

HTTP

Partie Serveur

de l’application

CGI

Servlets

ASP

ISAPI

Protocole*

Protocole*

Page 10: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Ressource oriented Approach

Service oriented Approach

REST versus WS-SOAP

ROA versus SOA

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr10

Page 11: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

REST pour une approche ROA

04/04/2017 Application Réparties – SI3 Jean-Yves tigli - [email protected] - www.tigli.fr 11

Serv

eur

Web

Liste des

Pièces

Détail

Pièce

Soumettre

BdC

HTTP GET URL 1

Réponse(doc XML / HTML)

Réponse(doc XML / HTML)

Réponse HTTP

Réponse HTTP

Réponse HTTP

HTTP GET URL 2

HTTP POST URL 3BdC

(XML/HTML)

URL du BdC

Page 12: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

La structure des messages

WS-REST

04/04/2017 Application Réparties – SI3 Jean-Yves tigli - [email protected] - www.tigli.fr 12

WS-REST message

HTTP headers (URI)

Content

Message complet

Entête standard HTTP and URL

et méthode CRUD

Donnée au format JSON, XML, …

GET, POST, PUT, DELETE

Format Data

Page 13: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

SOAP pour une approche SOA

04/04/2017 Application Réparties – SI3 Jean-Yves tigli - [email protected] - www.tigli.fr 13

getPartsList()

getPartId()

Submit(PO)

HTTP POST

URL 1

Réponse(doc XML) Réponse HTTP

Requête(doc XML)

Serv

eur

SOA

P

Serv

eur

Web

HTTP POST

URL 1

Réponse(doc XML) Réponse HTTP

Requête(doc XML)

HTTP POST

URL 1

Réponse(doc XML) Réponse HTTP

Requête(doc XML)

Page 14: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

La structure des

messages WS-SOAP

04/04/2017 Application Réparties – SI3 Jean-Yves tigli - [email protected] - www.tigli.fr 14

SOAP message

HTTP headers

SOAP Envelope

SOAP header

headers

SOAP body

method call & data

Message complet

Entête standard HTTP et

entête SOAP HTTP

Enveloppe

Entête

Entête individuelle

Corps contenant les appels

de méthodes SOAP

Appel de méthode et

description en XML des données

Page 15: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Web Service de type REST (WS-REST)

Les ressources sont identifiées par des URL

Architecture orientées

ressources

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr15

Page 16: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Les principes REST

REpresentational State Transfer

Style architectural pas seulement dédié aux

architectures orientées services et aux

communication entre machines.

Aucune hypothèse sur les protocoles impliqués,

seulement des contraintes

Les systèmes qui suivent les principes de

l'architecture REST sont souvent appelés RESTful et

s’appuient sur le Web

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr16

Chapitre 5 de la thèse de doctorat "Representational State Transfer (REST)". de Roy Fielding , 2000

Page 17: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Les principes REST ou ROA

Ressources (Identifiant)

– Entité identifiable dans le système (livre, agenda …)

– URI et donc possiblement URL

– Une URI identifie une seule Ressource

– Une Ressource peut avoir plusieurs URI

– Exemple :

Emploi du temps de tigli : /edt/prof/tigli/lundi

Méthodes (Verbes)

– Quatre opérations de base « CRUD » : Create (créer), Retrieve (lire), Update

(mettre à jour), Delete (Supprimer)

– Exemple méthodes HTTP : GET, POST, PUT, DELETE

– Déjà adaptées à la manipulation de Ressources

Représentation (Vue de l’état)

– Informations transférées entre client et serveur

– Exemple : XML, JSON, XHTML, CSV ….

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr17

Page 18: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Exemple RESTFul/XML

Exemple de message HTTP RESTFul

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr18

POST http://MyService/Person/Host: MyServiceContent-Type: text/xml; charset=utf-8Content-Length: 123<?xml version="1.0" encoding="utf-8"?>

<Person><ID>1</ID><Name>M Vaqqas</Name><Email>[email protected]</Email><Country>India</Country></Person>

Page 19: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Exemple RESTFul/JSON

Exemple de message HTTP RESTFul

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr19

POST http://MyService/Person/Host: MyServiceContent-Type: text/xml; charset=utf-8Content-Length: 123<?xml version="1.0" encoding="utf-8"?>

{"ID": "1","Name": "M Vaqqas","Email": "[email protected]","Country": "India"

}

Page 20: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

REST et invocation de méthode

Chaque demande REST contient une URL, de sorte

que le serveur sait quelle ressource vous souhaitez

accéder, mais il peut aussi contenir une méthode.

Une méthode décrit alors quoi faire avec cette

ressource.

Mais ce concept «méthode» n’est pas utilisé très

souvent car en marger d’une approche ROA

Habituellement, on utilise une URL comme un lien

vers des données récupérées via la méthode GET, et

modifiées (délétions, insertions, mises à jour) via la

méthode POST04/04/2017

Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr20

Page 21: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

WS-SOAP, WS-* du W3C

Achitecture orientée service

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr21

Page 22: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Exemple de requête SOAP

utilisant HTTP

Demande de cotation à un serveur :POST /StockQuote HTTP/1.1

Host: www.stockquoteserver.com

Content-Type: text/xml; charset=‘’utf-8’’

Content-Length: nnnn

SOAP-Action: ‘’Some-URI’’

<SOAP-ENV:Envelopexmlns:SOAP-ENV=‘’http://schemas.xmlsoap.org/soap/enveloppe/’’

SOAP-ENV:encodingStyle=‘’http://schemas.xmlsoap.org/soap/encoding/’’>

<SOAP-ENV:Body>

<m:GetLastTradePrice xmlns:m=‘’Some-URI’’>

<symbol>DIS</symbol>

</m:GetLastTradePrice>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr22

Une seule commande HTTP/POST

« envoi de message SOAP»

SOAP

Page 23: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Exemple de réponse SOAP

utilisant HTTP

Réponse du serveurHTTP/1.1 200 OK

Content-Type: text/xml; charset=‘’utf-8’’

Content-Length: nnnn

<SOAP-ENV:Envelope

xmlns:SOAP-ENV=‘’http://schemas.xmlsoap.org/soap/envelope/’’

SOAP-ENV:encodingStyle=‘’http://schemas.xmlsoap.org/soap/encoding/’’>

<SOAP-ENV:Body>

<m:GetLastTradePrice xmlns:m=‘’Some-URI’’>

<Price>34.5</Price>

</m:GetLastTradePrice>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr23

Réponse au HTTP/POST

SOAP

Page 24: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Modèle de message

SOAP permet une communication par message

– d’un expéditeur vers un récepteur

Structure d’un message

– Envelop (enveloppe)

Elément racine

Namespace : SOAP-ENV http://schemas.xmlsoap.org/soap/envelope/

– Header (entête)

Elément optionnel

Contient des entrées non applicatives (transactions, session, …)

– Body (corps)

Contient les entrées du message

– Nom d’une procédure, valeur des paramètres, valeur de retour

Peut contenir les éléments « fault » (erreurs)

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr24

Page 25: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Entête d’un message: Header

Contient des entrées non applicatives

– Transactions, sessions, …

L’attribut mustUnderstand par exemple

– Si absent ou =0 l’élément est optionnel pour l’application

réceptrice

– si =1, l’élément doit être compris par l’application réceptrice

sinon le traitement du message par le récepteur doit échouer

Exemple<SOAP-ENV:Header>

<t:Transaction xmlns:t=‘’Some-URI’’ SOAP-

ENV:mustUnderstand=‘’1’’>

</t:Transaction>

</SOAP-ENV:Header>

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr25

Page 26: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Corps d’un message

Contient des entrées applicatives

Encodage des entrées

Namespace pour l’encodage

– SOAP-ENC http://schemas.xmlsoap.org/soap/encoding/

– XSD : Schéma XML

Principe des règles d’encodage

– Les règles d’encodage définissent un système de type

SOAP utilise les conventions XSD

Les tableaux et les références sont typés de manière spécifique en utilisant XSD

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr26

Page 27: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Service WEB – Publication et

Découverte

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr27

Page 28: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Publication et Découverte

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr28

ApplicationCliente

Client

HTTP

Serveur

HTTP

Partie Serveur

de l’application

CGI

Servlets

ASP

ISAPI

Protocole*

Protocole*

Annuaire de Services WebURL et langage de Descriptionde Service Web …

DECOUVERTE

De

Service Web

PUBLICATION

De

Service Web

Page 29: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Langage de description d’un

Web service REST Essentiellement par

– API documentée sur une page WEB

– Par téléchargement d’une librairie pour le client

Plus récemment REST s’est doté d’un langage de

description de service : WADL (Web Application

Description Language)

– Soumis en 2009 au W3C, il n’est toujours pas standardisé

– Le WADL est un format de fichier basé sur XML qui permet de

décrire des applications REST.

– Cette spécification se heurte néanmoins à la spécification

WSDL 2.0, qui elle aussi permet la description de web services

REST.

– De plus, WADL est encore très mal supporté par l'ensemble des

frameworks existants ce qui limite son utilisation.

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr •29

Page 30: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Langage de description d’un

Web service SOAP: WSDL

Un langage dérivé d’XML : Web Service Description Language

Objectif

– Interface publique d’accès à un Web Service

– Comment communiquer pour utiliser le service (ensemble d’opérations et de messages abstraits reliés (bind) à des protocoles et des serveurs réseaux)

Grammaire XML (schema XML)

– Modulaire (import d’autres documents WSDL et XSD)

Séparation entre la partie abstraite et concrète

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr30

Page 31: Introduction aux Services Webnyx.unice.fr/wikifarm/fr.tigli.www/lib/exe/fetch.php?media=cours:cour… · Introduction aux Services Web 1 Département Sciences Informatiques ... –La

Les concepts de WSDL 1.1

<types>– Contient les définitions des types (utilise un système de

typage comme XSD)

<message>– Décrit les noms et types d’un ensemble de champs à

transmettre Paramètres d’une invocation, valeur du retour, …

<portType>– Décrit un ensemble d’opérations et les messages impliqués (0

ou 1 en entrée, 0 ou n en sortie). Partie la plus importante

<binding>– Spécifie une liaison d’un <porttype> à un protocole concret

(SOAP1.1, HTTP1.1, MIME, …). Un portType peut avoir plusieurs liaisons !

<port>– Spécifie un point d’entrée (endpoint) comme la combinaison

d’un <binding> et d’une adresse réseau

<service>– Pour agréger un ensemble de ports

04/04/2017Application Réparties – SI3 Jean-Yves tigli -

[email protected] - www.tigli.fr31

<portType>

<message>

<import>

<definitions>

<binding>

<types>

<documentation>

<service>