Web services (WS) Outline Intro on Middleware SOAP, HTTP binding WSDL UDDI Development tools References 2
Programming Trends Programming languages and software system evolve towards: higher levels of abstraction hiding hardware and platform details more powerful primitives and interfaces reducing the development and maintenance cost of the applications developed by facilitating their portability (e.g. Java) 3 Middleware as abstraction Middleware is mainly a set of programming abstractions: developed to facilitate the development of complex distributed systems to understand a middleware platform one needs to understand its programming model Programming abstraction gets higher underlying middleware infrastructure become more layered and complex 4
Middleware layers 5 Middleware for program abstraction Web Services apply existing abstractions to Internet SOAP like RPC, wrapped in XML, and mapped to HTTP to transport on Internet Evolution and appearance to the programmer is dictated by the trends in programming language RPC and C, CORBA and C++, RMI and Java, Web services 6
Middleware for integration Provide a full platform for developing and running complex distributed systems Trend is towards Service Oriented Architectures and standardization of interfaces Evolution is towards integration of platforms and flexible configuration 7 Distributed architectures Need for communicating across the net IIOP (Internet Inter-ORB Protocol) as CORBA/OMG standard protocol DCOM (Distribuited COM) as MS Windows standard RMI (Remote Method Invocation) as Java standard (RPC Remote Procedure Call) 8
Evolution Technology TCP/IP HTML + JSP XML + SOAP Functionality Connectivity Dynamic presentation Integration Innovation FTP, E-Mail, HTTP Web pages Web services Browsing the Web Programming the Web 9 Evolution of Distributed Arch. Component-Based Architectures Component-Based Distributed Architectures Web Services RPC binary/text XML RPC SOAP COM DCOM MSMQ CORBA IIOP Vendor Platform Language J2EE RMI JMS sync async 10
Problems Distributed protocols are very complex Communicating peers must share the same object model Firewall are critical points Protocols are too different 11 Definition of Web Service Web services are modular applications that are self-describing and that can be published, located, and invoked from anywhere on the web or within any local network based on open Internet standars 12
Definition of Web Service (2) Component that can invoked via the Internet by means of XML-based messages Can be made of (or used by) other web services Objectives Transparent with regard to h/w platforms, operating systems, programming languages, and proprietary standards Integration and collaboration among heterogeneous systems 13 Web Services: benefits Transparency Simplicity (!?) Reuse of an existing infrastructure (web) Loose coupling between components Software reuse 14
Element of WSs Discovery: where is the service? Description: what does the service? Invocation/Transport Discovery Description Invocation Transport 15 Elements of WSs (2) XML: standard for data representation SOAP: communication protocol WSDL: language describing the WS UDDI: registry for discovery UDDI WSDL SOAP/XML/XSD HTTP HTTPS TCP/IP 16
Scenario UDDI Registry Find (UDDI) WSDL Publish (UDDI) Service Requester Bind (SOAP + XML) Service Provider 17 The Web service cycle 1. Service Provider Creates Capability, and Registers interface 6. Reply is marshaled into another WSDL, and stuffed in a SOAP envelope 3. Consumer finds service and downloads interface 5. Provider parses request and WSDL performs service Service Provider Service Registry SOAP WSDL SOAP WSDL UDDI 2. Potential consumer searches registry for a suitable service WSDL 4. Consumer 7. Consumer consumes message composes request based on Service Consumer WSDL & packages it in SOAP envelope 18
Web Services Standard Bodies Main standard bodies relevant to Web services: W3C (World Wide Web Consortium) OASIS (Organization for the Advancement of Structured Information Standard WS-I (Web Services Interoperability Organization) 19 Web Services stack 20
WS standards & specifications 21 SOAP
SOAP Simple Object Access Protocol Simple and extensible communication protocol based on Internet standard XML for message format HTTP for transport (SOAP bindings) A SOAP message is an XML document describing a processing request or a result 23 Structure of a SOAP message Envelope: message container element Header: (optional) contains extensions Body: payload (e.g. request or response) Fault: (optional) informazion about errors (inside body) Envelope Header Header Entry Header Entry Body 24
Example <SOAP-ENV:Envelope xmlns:soap-env = "http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap-enc = "http://schemas.xmlsoap.org/soap/encoding"> <SOAP-ENV:Header>...</SOAP-ENV:Header> <SOAP-ENV:Body> <SOAP-ENV:Fault></SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 25 Use of Header <soap:envelope> <soap:header> <!-- If extension is not understood -- reject message and return error --> <t:transaction xmlns="tschemauri" mustunderstand="1"> <!-- Part of transaction no. 5 --> 5 </t:transaction> </soap:header> <soap:body>...</soap:body> </soap:envelope> 26
SOAP RPC IDL definition of remote method double GetStockQuote (in string symbol); How to invoke the servant with SOAP messages? 27 SOAP RPC request <SOAP-ENV:Envelope xmlns:soap-env="..."> <SOAP-ENV:Header/> Invoked <SOAP-ENV:Body> method <m:getstockquote xmlns:m="http://acme.it/ns/nyse"> <m:symbol>sunw<m:symbol> Arguments </m:getstockquote> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 28
SOAP RPC response <SOAP-ENV:Envelope xmlns:soap-env="..."> <SOAP-ENV:Header/> <SOAP-ENV:Body> Response <m:getstockquoteresponse xmlns:m="..."> <m:ret xsi:type="xsd:string"> 30.5 Return </m:ret> </m:getstockquoteresponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 29 HTTP primer Request/response protocol Stateless Tex-based protocol Single transaction per connection (1.0) Multiple transactions (1.1) Transfer of textual content Multimedia content with MIME (MIME header prepended as decodification hint) MIME-Version, Content-Type, Content-Transfer- Encoding 30
HTTP request messages GET Requests the specified document. The document is returned as text appended to the response POST Requests to send the appended text to the specified document for processing Command, Header, Data 31 HTTP POST request POST /cgi-bin/example HTTP/1.1 Content-type: text/plain Content-Length: 15 String to count 32
HTTP response message Return code (explanation), header, data Codici 1xx Informational (received, still working) 2xx Success 3xx Redirection 4xx Client error (bad request format) 5xx Server error (request OK, can't fulfill) 33 HTTP response message Successful response HTTP/1.1 200 OK Content-type: text/plain Content-Length: 2 15 Redirect HTTP/1.1 301 Moved Permanently Location: http://somewhere Content-Length: 0 34
HTTP extension headers 46 pre-defined headers New headers can be defined Ignored if not understood 35 HTTP binding POST method must be used Content type must be text/xml Return code for errors must be 500 (Internal Server Error) SOAP extension header must be present SOAPAction: "Some-URI" URI to be executed For firewalls (no content checking) 36
Example (Stock Quotes - req) POST /market HTTP/1.1 Content-Type: text/xml Content-Length: ### SOAPAction: "http://acme.it/market" <SOAP-ENV:Envelope> <SOAP-ENV:Header/> <SOAP-ENV:Body> <m:getstockquote> <m:symbol>sunw<m:symbol> </m:getstockquote> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 37 Example (Stock Quotes - ret) HTTP/1.1 200 OK Content-Type: text/xml Content-Length: ### <SOAP-ENV:Envelope> <SOAP-ENV:Header/> <SOAP-ENV:Body> <m:getstockquoteresponse> <m:ret>30.5</m:ret> </m:getstockquoteresponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 38
UDDI UDDI Universal Description, Discovery and Integration It specifies interfaces and behaviour of a Service Registry Organize Information per category (Taxonomy) and types of services offered 40
Struttura Many Industries (UDDI Operators) host a "UDDI Global Registry" Similar to DNS (with replication on ech node) UDDI Node UDDI Node UDDI Node UDDI.org UDDI Node 41 Informazioni di UDDI White pages: informazioni sui contatti dell'azienda fornitrice del servizio Yellow pages: informazioni relative alla categoria di appartenenza dell'azienda Green pages: informazioni tecniche relative al web service fornito dall'azienda 42
Scenario 1. Standard bodies populate the UDDI with description of various kinds of services 2. Service providers load descriptions of their exported service instances (together with company info, contact info, etc.) 3. Each service is assigned with a globally unique ID 4. Client retrieves location and description 5. Client invokes the service 43 WSDL
WSDL Web Services Description Language Consente di definire l niterfaccia dei servizi utilizzando un documento XML Un documento WSDL fornisce tutte le informazioni necessarie per l'utilizzo di un servizio web localizzazione, formato dei messaggi, protocollo di trasporto 45 Esempio Descrizione di un servizio che fornisce le temperature correnti delle capitali del mondo Il servizio fornisce un'unica operazione chiamata float GetCurrentTemp(in string city); e può essere utilizzata attraverso protocollo SOAP via HTTP 46
Esempio <SOAP-ENV:Envelope> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ct:getcurrenttemp> <ct:city>turin</ct:city> </ct:getcurrenttemp> </SOAP-ENV:Body> </SOAP-ENV:Envelope> request response <SOAP-ENV:Envelope> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ct:currenttempreply> <ct:temp>25.0</ct:temp> </ct:currenttemp> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 47 WSDL file structure <?xml version="1.0"?> <definitions> <documentation></documentation> <types></types> <message></message> <message></message> <porttype></porttype> <binding></binding> <service></service> </definitions> 48
Definition of a WSDL interface <?xml version="1.0"?> <definitions name="currenttemp" targetnamespace="http://example.com/ct.wsdl" xmlns:tns="http://example.com/ct.wsdl" xmlns:ct="http://example.com/ct.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap" xmlns="http://schemas.xmlsoap.org/wsdl"> <documentation> Temperatures of capital cities </documentation> </definitions> 49 <types> <schema targetnamespace="http://example.com/ct.xsd" xmlns="http://www.w3.org/2000/10/xmlschema"> <element name="currenttempreq"> <complextype> <element name="city" type="sting"> </complextype> </element> <element name="currenttempreply"> <complextype> <element name= Temp" type="float"> </complextype> </element> </schema> </types> Types in WSDL 50
Messages Types can be used to compose messages format used by the Web Service <message name="getcurrenttempinput"> <part name="body" element="ct:currenttempreq"/> </message> <message name="getcurrenttempoutput"> <part name="body" element="ct:currenttempreply"/> </message> 51 Operations Define how to use messages to execute an operation <porttype name="currenttempporttype"> <operation> <input message="tns:getcurrenttempinput"/> <output message="tns:getcurrenttempoutput"/> </operation> </porttype> 52
Binding Modalita' di accesso ad una operazione esportata Binding Schema di comunicazione 53 <binding name="currenttempbind" type="tns:currenttempporttype"> <soap:binding style="rpc" transport="http"/> <operation name="getcurrenttemp"> <soap:operation soapaction="http://example.com/getcurrenttemp"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </wsdl:binding> 54
Communication Schema One-way <operation><input/></operation> Request/Response <operation><input/><output/></operation> Solicit/Response <operation><output/><input/></operation> Notification <operation><output/></operation> 55 Service specification Service specification Which operations are provided (port) Which binding style Where (URI) <service name="currenttempservice"> <port name="currenttempport" binding="tns:currenttempbind"> <soap:address location="http://example.com/currenttemp"/> </port> </service> 56
Web Services Development Toolkits SUN WSDP Web Services Developers Pack Apache AXIS (open source) Provides server-side infrastructure for deploying SOAP services on Java Web Container Provides client-side API for invoking SOAP services HTTP, SMTP Xerces: XML parsers in Java, C++ Xalan: XSLT stylesheet processors 58
Toolkits Microsoft SOAP toolkit Provides the infrastructure suitable for building, publishing, exploiting a web service using the Visual Studio 6.0 environment Provides a SOAP listener (HTTP) Provides wizards to convert already existing COM components to web services Provides wizards to extract the WSDL description starting from the COM/DCOM code 59 Development platforms SUN ONE (Sun Microsystem) Visual Studio.NET (Microsoft) Eclipse Plug-ins IBM WebSphere 60
References W3C docs XML, www.w3.org/tr/rec-xml/ NS, www.w3.org/tr/rec-xml-names/ Schema, www.w3.org/tr/xmlschema-0/ SOAP, www.w3.org/tr/soap/ WSDL, www.w3.org/tr/wsdl/ 61 References UDDI www.uddi.org/specification.html Java Web Services Tutorial java.sun.com/webservices/ Microsoft MSDN Library msdn.microsoft.com/library/ 62