Web services (WS)
Outline
Intro on Middleware SOAP, HTTP binding WSDL UDDI Development tools References3
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)
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
5
Middleware layers
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
7
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
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
9
Evolution
TCP/IP HTML + JSP XML + SOAP Technology
Functionality Connectivity presentationDynamic Integration
Innovation FTP, E-Mail, HTTP Web pages Web services
Browsing the Web
Programming the Web
Evolution of Distributed Arch.
COM CORBA DCOM IIOP RMI RPC JMS MSMQ XML RPC SOAP Component-Based Architectures Component-Based Distributed
Architectures Web Services binary/text async Vendor Platform Language sync J2EE
11
Problems
Distributed protocols are very complex
Communicating peers must share the
same object model
Firewall are critical points Protocols are too different
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
13
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
Web Services: benefits
Transparency
Simplicity (!?)
Reuse of an existing infrastructure (web)
Loose coupling between components
15
Element of WSs
Discovery: where is the service? Description: what does the service?
Invocation/Transport Invocation Description Discovery Transport
Elements of WSs (2)
XML: standard for data representation
SOAP: communication protocol
WSDL: language describing the WS
UDDI: registry for discovery
SOAP/XML/XSD WSDL UDDI HTTP HTTPS TCP/IP
17
Scenario
Find (UDD I) Pub lish (U DD I) WSDL Bind (SOAP + XML) Service Requester UDDI Registry Service Provider WSDL WSDLThe Web service cycle
Service Provider WSDL 1. Service Provider Creates Capability, and Registers interface Service Registry 2. Potential consumer searches registry for a suitable service Service Consumer UDDI 3. Consumer finds service and downloads interface WSDL 4. Consumer composes request based on WSDL & packages it in SOAP envelope SOAP 5. Provider parses request and performs service 6. Reply is marshaled into another WSDL, and stuffed in a SOAP envelope SOAP 7. Consumer consumes message
19
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)
21
WS standards & specifications
23
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
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
Body
Header Entry Header Entry
25
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>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>
27
SOAP RPC
IDL definition of remote method
double GetStockQuote
(in string symbol);
How to invoke the servant with SOAP
messages?
SOAP RPC request
Invoked method Arguments <SOAP-ENV:Envelope xmlns:SOAP-ENV="..."> <SOAP-ENV:Header/> <SOAP-ENV:Body> <m:GetStockQuote xmlns:m="http://acme.it/ns/nyse"> <m:symbol>SUNW<m:symbol></m:GetStockQuote> </SOAP-ENV:Body>
29
SOAP RPC response
<SOAP-ENV:Envelope xmlns:SOAP-ENV="..."> <SOAP-ENV:Header/> <SOAP-ENV:Body> <m:GetStockQuoteResponse xmlns:m="..."> <m:ret xsi:type="xsd:string"> 30.5 </m:ret> </m:GetStockQuoteResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Return ResponseHTTP 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
31
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
HTTP POST request
POST /cgi-bin/example HTTP/1.1 Content-type: text/plain
Content-Length: 15 String to count
33
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)
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: 035
HTTP extension headers
46 pre-defined headers
New headers can be defined
Ignored if not understood
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
37
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>
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>
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
41
Struttura
Many Industries (UDDI Operators) host
a "UDDI Global Registry"
Similar to DNS (with replication on ech node) UDDI.org UDDI.org UDDI Node UDDI Node UDDI Node UDDI Node UDDI Node UDDI Node UDDI Node UDDI Node
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
43
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
45
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
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
47
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> <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> request responseWSDL file structure
<?xml version="1.0"?> <definitions> <documentation></documentation> <types></types> <message></message> <message></message> <portType></portType> <binding></binding> <service></service> </definitions>49
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> <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>
51
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>
Operations
Define how to use messages to
execute an operation
<portType name="CurrentTempPortType"> <operation>
<input message="tns:GetCurrentTempInput"/> <output message="tns:GetCurrentTempOutput"/> </operation>
53
Binding
Modalita' di accesso ad una operazione
esportata Binding
Schema di comunicazione
<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>
55
Communication Schema
One-way <operation><input/></operation> Request/Response <operation><input/><output/></operation> Solicit/Response <operation><output/><input/></operation> Notification <operation><output/></operation>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>
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++
59
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
Development platforms
SUN | ONE (Sun Microsystem)
Visual Studio .NET (Microsoft) Eclipse Plug-ins
61
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/References
UDDI www.uddi.org/specification.html Java Web Services Tutorialjava.sun.com/webservices/
Microsoft MSDN Library