Web Services gjennom eksempler Johannes Brodwall Innhold Hvorfor
Web Services gjennom eksempler Johannes Brodwall
Innhold • Hvorfor – integrasjon, det tjenesteorienterte nettet • Hva – XML, SOAP, WSDL og HTTP • Hvordan – Visual Studio. NET, Axis, J 2 EE 1. 4, Ruby Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 2
Viktige organisasjoner • OASIS (Organisation for the Advancement of Structured Information Standards) – Viktigste bidrag: eb. XML • W 3 C (World Wide Web Consortium) • WS-I (Web-Services Interoperability) • IBM, Microsoft: – Utvikler de fleste delstandardene Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 3
Fra tcp til the semantic web 1980 -tallet Sockets FTP/telnet/ gopher 1990 -1995 -2000 -2005 Web Service http/soap Web Browser http/html Kommunikasjon Integrasjon av bedriftens siloer Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com Fremtiden The Semantic Web Samarbeid med partnere Dynamisk transformasjon Discovery 4
Hva er Web Services ”A Web Service is application logic that is accessible using standard Internet protocols. ” [ Keith Ballinger ] Like components, Web Services represent black-box functionality that can be used and reused without regard to how the service is implemented. Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 5
Fordeler • INTEGRASJON • Hetrogene parter • Debugbar protokol • Nettverksvennlig teknologi Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 6
To ting • Arkitektur • Teknologier • • • SOAP • WSDL • HTTP Komponentbasert Distribuert Åpen Innkapslet Tjenesteorientert Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 7
Tjenesteorientert • Grovkornet • Verdi til ”kunder” • Standardisert grensesnitt In an SOA, resources are made available to other participants in the network as independent services that are accessed in a standardized way. This provides for more flexible loose coupling of resources than in traditional systems architectures. [ http: //looselycoupled. com ] Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 8
Bokstavsuppe • XML – e. Xtensible Markup Language – Standard for å strukturere tekst-dokumenter – Presenterer en hierarkisk struktur • SOAP – Simple Object Access Protocol – XML standards for metodekall – Data som utveksles mellom tjenestene • WSDL – Web Services Definition Language – XML standard for tjenestebeskrivelse – Brukes for å finne ut hvordan en tjeneste skal kalles Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 9
Eksempel. NET klient J 2 EE klient . NET server J 2 EE Server Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com Ruby klient Ruby Server 10
Web Service Servere • Støtte i utviklingsmiljø tar hånd om det meste – nesten som å skrive vanlige klasser • Utvikles som stateless klasser eller metoder i språket • Publiseres automatisk, via en descriptor, eller programmatisk • Normalt vil servermiljøet generere WSDL automatisk Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 11
Arkitektur (Axis) Marshall/ unmarshal Transport Management WSDL generation Custom handlers Our Service Web Service Container (Axis) HTTP applikasjonsserver (Tomcat) Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 12
Java Server // Hello. Web. Service. jws // is placed in axis webapp directory // Axis autocompiles JWS-files public class Hello. Web. Service { public String say. Hello. To(String name) { System. out. println("Hello web services says hello to " + name); return "Hello from Axis, " + name; } } Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 13
. NET Server using System; using System. Diagnostics; using System. Web. Services; namespace Kompis. Dot. Net. Service { [Web. Service(Namespace="http: //brodwall. no/demo/kompis 2004 -01 -20/ ")] public class Hello. Service : Web. Service { [Web. Method] public string say. Hello. To(string name) { Debug. Write. Line("Hello web services says hello return "Hello from. NET, " + name; } to " + name); } } Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 14
Ruby Server require 'soap/rpc/standalone. Server' class Hello. World. Server < SOAP: : RPC: : Standalone. Server def on_init add_method(self, 'hello_world', 'from') end def hello_world(from) puts "Hello web services says hello to " + from "Hello from Ruby, #{ from }" end Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 15
Web Service klienter • Automatisk genererte ”stubs” for enklere bruk – Nesten som vanlig bruk av klasser • Dynamisk kall • Dynamisk ”discovery” – ikke vist Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 16
. NET Client. . . private void button. Exec_Click(object sender, System. Event. Args e) { Hello. Axis. Hello. Web. Service service = new Hello. Axis. Hello. Web. Service (); text. Box. Response. Text = service. say. Hello. To(text. Box. Name. Text); }. . . Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 17
Java Client (JAX-RPC style) // Generated with the Axis WSDL 2 Java tool import no. brodwall. demo. kompis 2004_01_20. Hello. Service. Locator; import no. brodwall. demo. kompis 2004_01_20. Hello. Service. Soap; public class Java. Client. Of. Dot. Net { public static void main(String[] args) throws Exception { Hello. Service. Locator locator = new Hello. Service. Locator(); Hello. Service. Soap service = locator. get. Hello. Service. Soap(); System. out. println(service. say. Hello. To("JAX-RPC client")); } } Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 18
Java Client import java. rmi. Remote. Exception ; javax. xml. rpc. Service. Exception ; org. apache. axis. client. Call ; org. apache. axis. client. Service ; public class Low. Level. Client { public static void main(String[] args) throws Exception { Service service = new Service(); Call call = (Call)service. create. Call(); call. set. Target. Endpoint. Address ( "http: //localhost: 1234/axis/Hello. Web. Service. jws" ); call. set. Operation. Name("say. Hello. To"); String result = (String)call. invoke(new Object[] { "Simple Axis client" }); System. out. println("Result: " + result); } } Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 19
Ruby Clients # Hello. Web. Service stub is created by wsdl 2 ruby require 'default. Driver. rb' service = Hello. Web. Service. new() puts service. say. Hello. To("Ruby") # Manual calling require 'soap/rpc/driver' endpoint = "http: //localhost: 8080/axis/Hello. Web. Service. jws" service = SOAP: : RPC: : Driver. new(endpoint, nil) service. add_method("say. Hello. To", "name") service. say. Hello. To("Ruby") Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 20
Invocation Framework • I praksis er den manuelle metoden vanskelig å bruke – Forskjellige servere trenger forskjellig informasjon – Det kan være tidkrevende å sette opp • WSIF (http: //ws. apache. org/wsif) løser dette ved å dynamisk generere kallobjekter fra WSDL Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 21
Første inntrykk • Enkel integrasjon av homogene miljøer • Blir mer problematisk med: – Utveksling av komplekse datastrukturer – Bruk av standard typer i forskjellige språk – Exceptions fra serveren Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 22
SOAP Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 23
SOAP - request <? xml version="1. 0" encoding="us-ascii" ? > <env: Envelope xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: env="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <env: Body> <say. Hello. To env: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <name xsi: type="xsd: string">Ruby</name> </say. Hello. To> </env: Body> </env: Envelope> Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 24
SOAP - response <? xml version="1. 0" encoding="UTF-8"? > <soapenv: Envelope xmlns: soapenv="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <soapenv: Body> <say. Hello. To. Response soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" > <say. Hello. To. Return xsi: type="xsd: string">Hello from Axis, Ruby</say. Hello. To. Return> </say. Hello. To. Response> </soapenv: Body> </soapenv: Envelope> Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 25
SOAP meldinger • Består av Envelope, Header og Body • Header kan inneholde protokollutvidelser – Transaksjoner – Sikkerhet – Logging – Kryptering • Body inneholder selve meldingen – Kan også inneholde Faults • Multipart – kan inneholde flere deler Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 26
Web Services Definition Language • Beskriver tjenester, dataformater og endepunkt • Skal definere ”alt som trengs” for å kunne kommuniserer med tjenesten Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 27
WSDL - outline <? xml version="1. 0" encoding="UTF-8"? > <wsdl: definitions target. Namespace="http: //localhost: 8080/axis/Hello. Web. Service. jws" xmlns="http: //schemas. xmlsoap. org/wsdl/" xmlns: apachesoap="http: //xml. apache. org/xml-soap" xmlns: soapenc="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: wsdl="http: //schemas. xmlsoap. org/wsdl/" xmlns: wsdlsoap="http: //schemas. xmlsoap. org/wsdl/soap/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema"> <wsdl: message. . . > <wsdl: port. Type name="Hello. Web. Service"> <wsdl: operation. . . > <wsdl: input. . . > <wsdl: output. . . > <wsdl: binding. . . > <wsdl: operation. . . > <wsdl: service. . . > </wsdl: definitions> Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 28
WSDL - interface <wsdl: message name="say. Hello. To. Response"> <wsdl: part name="say. Hello. To. Return" type="xsd: string"/> </wsdl: message> <wsdl: message name="say. Hello. To. Request"> <wsdl: part name="name" type="xsd: string"/> </wsdl: message> <wsdl: port. Type name="Hello. Web. Service"> <wsdl: operation name="say. Hello. To" parameter. Order="name"> <wsdl: input message="impl: say. Hello. To. Request" name="say. Hello. To. Request"/> <wsdl: output message="impl: say. Hello. To. Response" name="say. Hello. To. Response"/> </wsdl: operation> </wsdl: port. Type> Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 29
WSDL - implementation <wsdl: binding name="Hello. Web. Service. Soap. Binding " type="impl: Hello. Web. Service "> <wsdlsoap: binding style="rpc" transport=" http: //schemas. xmlsoap. org/soap/http"/> <wsdl: operation name="say. Hello. To"> <wsdlsoap: operation soap. Action=""/> <wsdl: input name="say. Hello. To. Request"> <wsdlsoap: body encoding. Style=" http: //schemas. xmlsoap. org/soap/encoding/" namespace=" http: //Default. Namespace" use="encoded"/> </wsdl: input> <wsdl: output name="say. Hello. To. Response "> <wsdlsoap: body encoding. Style=" http: //schemas. xmlsoap. org/soap/encoding/" namespace=" http: //localhost: 8080/axis/Hello. Web. Service. jws" use="encoded"/> </wsdl: output> </wsdl: operation> </wsdl: binding> <wsdl: service name="Hello. Web. Service "> <wsdl: port binding=" impl: Hello. Web. Service. Soap. Binding" name="Hello. Web. Service"> <wsdlsoap: address location=" http: //localhost: 8080/axis/Hello. Web. Service. jws"/> </wsdl: port> </wsdl: service> Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 30
WSDL <? xml version="1. 0" encoding="UTF-8"? > <wsdl: definitions target. Namespace="http: //localhost: 8080/axis/Hello. Web. Service. jws" xmlns="http: //schemas. xmlsoap. org /wsdl/" xmlns: apachesoap="http: //xml. apache. org /xml-soap" xmlns: impl="http: //localhost: 8080/axis/Hello. Web. Service. jws" xmlns: intf="http: //localhost: 8080/axis/Hello. Web. Service. jws" xmlns: soapenc="http: //schemas. xmlsoap. org /soap/encoding/" xmlns: wsdl="http: //schemas. xmlsoap. org /wsdl/" xmlns: wsdlsoap="http: //schemas. xmlsoap. org /wsdl/soap/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema"> <wsdl: message name="say. Hello. To. Response "> <wsdl: part name="say. Hello. To. Return " type="xsd: string "/> </wsdl: message> <wsdl: message name="say. Hello. To. Request "> <wsdl: part name="name" type="xsd: string "/> </wsdl: message> <wsdl: port. Type name="Hello. Web. Service "> <wsdl: operation name="say. Hello. To " parameter. Order="name "> <wsdl: input message="impl: say. Hello. To. Request " name="say. Hello. To. Request "/> <wsdl: output message="impl: say. Hello. To. Response " name="say. Hello. To. Response "/> </wsdl: operation> </wsdl: port. Type> <wsdl: binding name="Hello. Web. Service. Soap. Binding " type="impl: Hello. Web. Service "> <wsdlsoap: binding style="rpc" transport="http: //schemas. xmlsoap. org /soap/http"/> <wsdl: operation name="say. Hello. To "> <wsdlsoap: operation soap. Action=""/> <wsdl: input name="say. Hello. To. Request "> <wsdlsoap: body encoding. Style="http: //schemas. xmlsoap. org /soap/encoding/" namespace="http: //Default. Namespace " use="encoded"/> </wsdl: input> <wsdl: output name="say. Hello. To. Response "> <wsdlsoap: body encoding. Style="http: //schemas. xmlsoap. org /soap/encoding/" namespace="http: //localhost: 8080/axis/Hello. Web. Service. jws" use="encoded"/> </wsdl: output> </wsdl: operation> </wsdl: binding> <wsdl: service name="Hello. Web. Service "> <wsdl: port binding="impl: Hello. Web. Service. Soap. Binding " name="Hello. Web. Service "> <wsdlsoap: address location="http: //localhost: 8080/axis/Hello. Web. Service. jws"/> </wsdl: port> </wsdl: service> </wsdl: definitions > Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 31
UDDI • Universal Discovery, Directory Integration • Tenkt som ”gule sider” for web services • Forutsetter standardisering på WSDL-nivå • http: //www. ibm. com/developerworks/w ebservices/library/ws-eight/ Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 32
Begrensninger • Datainnhold – Struktur – Spesifikke typer – Standardiserte grensesnitt • Request-response-basert – Ingen callbacks (WS-Callback) – (Normalt) Synkront (S 070 -S 071) • Standarder sent og ikke generelt implementert – Sikkerhet (WS-Security) – Transaksjoner (WS-Transactions, WS-Coordination) – Se http: //www. w 3. org/TR/ws-arch-scenarios/ Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 33
Fremtiden slik jeg ser den • WS-Security, WS-Transactions får bredere implementasjoner • UDDI forblir en kuriositet – Bransjestandarder lar vente på seg • Semantic web forblir en drøm Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 34
Diskusjon • • • Når er SOAP verd overheaden? Vil det fungere i våre situasjoner? Hvordan komme i gang? Kommer det til å bli standardisering av tjenester? I hvilken grad ønsker vi dynamisk discovery? – Stoler vi på at programmet velger riktig leverandør? – Vil automatiske ”meglere” krasje ”det frie marked”? Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 35
Konklusjon • Web services integrerer hetrogene tjenester • Fungere bra for enkle tjenester • Krever mer jobb med komplekse tjenester • Web Services er ment til å være en del av dynamisk discovery Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 36
Stikkord • Axis – Apache Web Service rammeverk • JAX-RPC – Java API for XML Remote Procedure Calls • J 2 EE 1. 4 – viktige forbedringer i JAX-RPC • WS-I, WS-Security • The Semantic Web Copyright 2004 – Brodwall IT Services (BITS) johannes@brodwall. com 37
- Slides: 37