27
1 Web-Programmierung (WPR) Vorlesung X. Web Services Teil 2 mailto:[email protected]

Vorlesung X. Web Services Teil 2

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Vorlesung X. Web Services Teil 2

1

Web-Programmierung (WPR)

Vorlesung X.

Web ServicesTeil 2

mailto:[email protected]

Page 2: Vorlesung X. Web Services Teil 2

2

21 Web Service

● World Wide Web seit Anfang 1990er Jahren

Web-Browser

Web-ServerMenschGeschäfts-

logik(Business)

Applikationszentriertes Web

ApplikationXMLover

HTTP

HTTP

Page 3: Vorlesung X. Web Services Teil 2

3

Application Server

21.1 Grundlagen

Web-ServiceClient

UDDI-Registry

Web-Container

WSDL

Discovery

SOAPover

HTTP

Web ServicesSubsystem

SOAP

Container

Business-Komponente

Business-Komponente

Business-Komponente

Business-Komponente

Web-Server

Basisarchitektur

Page 4: Vorlesung X. Web Services Teil 2

4

21.1 XML-RPC

● Remote Method Invocation via XML

XML-RPC-Definition

Page 5: Vorlesung X. Web Services Teil 2

5

21.1 XML-RPC

● Alternative XML-RPC http://www.xmlrpc.com<?xml version="1.0"?><methodCall> <methodName>warenkorb.addPosition </methodName>

<params> <param> <value>Monitor</value> </param> <param> <value><int>10</int></value> </param> </params></methodCall>

Page 6: Vorlesung X. Web Services Teil 2

6

21.1 XML-RPC

● XML-RPC Response<?xml version="1.0"?><methodResponse> <fault><value><struct> <member> <name>faultCode</name> <value><int>4</int></value> </member> <member> <name>faultString</name> <value><string>Too many params. </string> </value>

</member> </struct></value></fault></methodResponse>

Page 7: Vorlesung X. Web Services Teil 2

7

21.2 SOAP

● Simple Object Access Protocol(Alternative zu XML-RPC)

● Findet breite Unterstützung in Industrie● IBM -> Apache -> Apache Axis● Plattformunabhängig + XML-basiert● W3C Standard seit 2000 (Version 1.1)● SOAP-Spezifikation

Message-Syntax Regeln für Codierung von Datentypen

● Aktuelle Version 1.2● ca. 60 Implementierungen (Stand 2004)

Page 8: Vorlesung X. Web Services Teil 2

8

21.2 SOAP

21.2 SOAP...<xsd:element name="Envelope" type="tns:Envelope"/><xsd:complexType name="Envelope"><xsd:sequence>

<xsd:element ref="tns:Header" minOccurs="0"/><xsd:element ref="tns:Body" minOccurs="1"/> </xsd:sequence>

</xsd:complexType>....

Page 9: Vorlesung X. Web Services Teil 2

9

21.2 SOAP

● Nachrichtenformat

SOAP Message

SOAP-Envelope

SOAP-Header

SOAP-Body

SOAP-Body (RPC)● Service● Methode● Parameter

DOCUMENT● Beliebiges

XML-Dokument

Page 10: Vorlesung X. Web Services Teil 2

10

21.2 SOAP

● Beispiel:double getQuote(String id);

Request<soapenv:Envelope ...> <soapenv:Body> <ns1:getQuote xmlns:ns1=“http...“>

<id xsi:type=“xsd:string“>401</id> </ns1> </soapenv:Body></soapenv:Envelope>Missing Namespaces:● xmlns:soapenv, xmlns:xsd, xmlns:xsi

Page 11: Vorlesung X. Web Services Teil 2

11

21.2 SOAP

● Beispiel:double getQuote(String id);

Response<soapenv:Envelope ...> <soapenv:Body> <ns1:getQuoteResponse xmlns:ns1=“..“> <ns1:quoteReturn xsi:type=“xsd:double“> 19.5</ns1:quoteReturn> </ns1:getQuoteResponse> </soapenv:Body></soapenv:Envelope>Missing Namespaces:● xmlns:soapenv, xmlns:xsd, xmlns:xsi

Page 12: Vorlesung X. Web Services Teil 2

12

21.2 SOAP

● Beispiel:double getQuote(String id);

Response (bei Fehler)<soapenv:Envelope ...> <soapenv:Body> <soapenv:Fault>

<faultcode>Server.error</faultcode><faultstring>no such op.</faultstring>

</soapenv:Fault> </soapenv:Body></soapenv:Envelope>Missing Namespaces:● xmlns:soapenv, xmlns:xsd, xmlns:xsi

Page 13: Vorlesung X. Web Services Teil 2

13

21.2 SOAP

● Transport HTTP, SMTP, FTP , ... Auswahl => Binding

● HTTP-Übertragung HTTP-Request => SOAP-Request HTTP-Response => SOAP-Response

Page 14: Vorlesung X. Web Services Teil 2

14

21.2 SOAP

● HTTP-Header SOAP Request

POST /axis/services/vinoExchange HTTP/1.0Content-Type: text/xml; charset=utf-8Accept: application/soap+xml, mulipart-related, text/*

Host:127.0.0.1SOAPAction:““Content-Length: 449<?xml..><soapEnvelope> ....</soapEnvelope>

Page 15: Vorlesung X. Web Services Teil 2

15

21.2 SOAP

● HTTP-Header SOAP Response

HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Date:: ...Server:Apache Coyote/1.0Connection:close<?xml..><soapEnvelope> ....</soapEnvelope>

Page 16: Vorlesung X. Web Services Teil 2

16

21.2 SOAP

SOAP Message

MIME HeaderSOAP-Envelope

SOAP-Header

SOAP-Body

SOAP-Part

SOAP-Part

● SOAP-Messagemit Attachments

Page 17: Vorlesung X. Web Services Teil 2

17

21.2 SOAP

● HTTP-Header SOAP RequestPOST /soap/servlet/messagerouter HTTP/1.0Content-Type: mulitpart/related; boundary:“----=_Part_0_747212.10269376“;SOAPAction:“urn:vinoexchange:interest“----=_Part_0_747212.10269376Content-Type: text/xml;charset=utf-8<soapEnvelope> ...</soapEnvelope>----=_Part_0_747212.10269376Content-Type:image/gif.........----=_Part_0_747212.10269376

Page 18: Vorlesung X. Web Services Teil 2

18

21.3 WSDL

● Web Service Description Language

Öffentliche Methoden mit Signaturen

Unterstützte Transport Protokolle

Adresse des Web Services

Typ-Schemata für den Datenaustausch

=> Schnittstellenbeschreibung (IDL)

Page 19: Vorlesung X. Web Services Teil 2

19

21.3 WSDL

<wsdl:definitions>

<wsdl:types>

<wsdl:message>

<wsdl:portType>

<wsdl:binding>

<wsdl:service>

Page 20: Vorlesung X. Web Services Teil 2

20

21.3 WSDL

<wsdl:definitions>

<wsdl:types>

<wsdl:message>

<wsdl:portType>

<wsdl:binding>

<wsdl:service>

● wsdl:types

<wsdl:types> <xs:schema>

<xs:element name="orderItem"> <xs:complexType> <xs:sequence> <xs:element ref="description"/> </xs:sequence> <xs:attribute name="amount"

use="required" type="xs:integer"/> <xs:attribute name="orderId" use="required" type="xs:integer"/> </xs:complexType> </xs:element> </xs:schema>

</wsdl:types>

Page 21: Vorlesung X. Web Services Teil 2

21

21.3 WSDL

<wsdl:definitions>

<wsdl:types>

<wsdl:message>

<wsdl:portType>

<wsdl:binding>

<wsdl:service>

● wsdl:portType abstrakte WebService Schnittstelle

<wsdl:portType name=“CalculatePort“>

<wsdl:operation name=“addValue“> <wsdl:input/> <wsdl:output/> </wsdl:operation><wsdl:portType>

Page 22: Vorlesung X. Web Services Teil 2

22

21.3 WSDL

● wsdl:portType – Abstrakte Schnittstelle 1..n Operationenen

Operation BeschreibungOne-Way Client sendet Nachricht ohne Response zu

erwartenRequest-Response Client sendet Nachricht an Service und dieser

reagiert mit ResponseSolicit-Response Service sendet Nachricht anClient und

bekommt von diesem eine ResponseNotification Der WebService sendet Nachricht an den Client

Page 23: Vorlesung X. Web Services Teil 2

23

21.3 WSDL

<wsdl:definitions>

<wsdl:types>

<wsdl:message>

<wsdl:portType>

<wsdl:binding>

<wsdl:service>

● wsdl:message (Nachrichten)

<wsdl:message name=“getQuoteReq“><wsdl:part name=“id“ type=“xsd:string“/>

</wsdl:message>

Page 24: Vorlesung X. Web Services Teil 2

24

21.3 WSDL

<wsdl:definitions>

<wsdl:types>

<wsdl:message>

<wsdl:portType>

<wsdl:binding>

<wsdl:service>

● wsdl:binding Bindung an ProtokollNachrichtenprotokoll

<wsdl:binding name=“CalculatePort“>

<wsdl:soapbinding style=“rpc“ transport=“http:..“> <wsdl:operation> </wsdl:operation> </wsdl:soapbinding><wsdl:binding>

„http://schemas.xmlsoap.org/soap/http“

Page 25: Vorlesung X. Web Services Teil 2

25

21.3 WSDL

<wsdl:definitions>

<wsdl:types>

<wsdl:message>

<wsdl:portType>

<wsdl:binding>

<wsdl:service>

● wsdl:service 1..n -> Port

<wsdl:service name= “CalculateService“>

<wsdl:port name=““> <wsdl:address location=“http://.“> </wsdl:address> </wsdl:port><wsdl:service>

Page 26: Vorlesung X. Web Services Teil 2

26

21.3 WSDL

<wsdl:definitions>

<wsdl:types>

<wsdl:message>

<wsdl:portType>

<wsdl:binding>

<wsdl:service>

● wsdl:definitions(Namensräume)

<wsdl:definitions xmlns:wsdl=“...“ targetNamespace=“...“ xmlns:wsdlsoap=“...“ xmlns:soapenc=“...“

></wsdl:definitions>

Page 27: Vorlesung X. Web Services Teil 2

27

21.3 WSDL

Developing a Web Service ?

How ?

Where to start ?