Web Services

Download Report

Transcript Web Services

Web Services
Index
- Overview
- SOAP
- WSDL
- UDDI
- Performance
basado en UPC-DAC/FIB-AAD Jordi Torres; v2.0-05/04
1
Web Services
 What are web services?
-
-
-
Web services are modular web applications that
provide data and services to other applications over the
web
Web services apply web technologies such as HTTP
and XML to the concepts of distributed computing
technologies such as CORBA and DCOM
Aplicaciones auto-contenidas, auto-escritas que
pueden ser publicadas, localizadas e invocadas a
través de la Web
2
Web Service Examples
A stock quote service.
A weather service, a map service, a web
search service…
- any composition of Web services.
e.g. Dollar Rent-A-Car
- Create standard interfaces so business partners
could tap into the company's car reservation
system.
Google, Amazon, …
http://www.google.com/apis/
3
What are Web Services?
 Today’s web:
-
Web designed for application to human interactions
-
Enabled B2C e-commerce.
Non-automated B2B interactions.
• Information sharing: a distributed content library.
• Built on very few standards: http + html
• Shallow interaction model: very few assumptions made about
computing platforms.
 “Web services” is an effort to build a distributed
computing platform for the Web.
-
Services available via the Web.
Meant mainly for application to application communication
(as opposed to users directly)
Enables Business-to-Business transactions.
E.g., a web service is contacted on a URL using the SOAP
protocol over HTTP.
4
Complete picture of distributed
applications (using WS)
5
Core technologies used for WS
 XML
 SOAP
- Simple Object Access Protocol
- a framework for exchanging XML-based information in a network
- the currently most hyped XML/Web service technology
 WSDL
-
Web Service Description Language
an XML-based language for describing network services
WSDL descriptions of capabilities and locations of services
like an interface description language for Web services
communication using SOAP or direct HTTP
 UDDI
- Universal Description, Discovery, and Integration
- provides a registry mechanism for clients and servers to find each
other
- uses SOAP for communication
6
Otra definición
Programas accesibles en Internet que
exponen su funcionalidad
recibiendo/enviando mensajes SOAP a
través de HTTP(s) y describen su
interfaz en WSDL
7
The Web Services Stack
Service
Publication/Discovery
UDDI
Service
Description
WSDL
XML Messaging
SOAP
Transport Network
HTTP, SMTP, MQSeries, etc.
8
9
What is SOAP?
SOAP is a lightweight protocol for exchange
of information in a decentralized, distributed
environment using XML.
10
The Simple Object Access
Protocol (SOAP)
XML-based protocol for messaging and RPC
- Can works on top of existing transports
• HTTP, SMTP, FTP, MQSeries
Use of XML schema for encoding typed values
Language independent
- Generation of SOAP messages available in popular
programming language
• C, Java, Perl
11
SOAP: FORMATO GENERAL
Envelope
Header
Header Key
Header Key
Body
12
SOAP: Formato general
SOAP especifica el formato de mensajes
Envelope: datos globales (codificación, espacio de
nombres, ...)
contiene: header (opcional) + body (obligatorio)
Body:contiene datos en formato XML
Header: contiene meta-informaticón
13
Sample HTTP Interaction
(C) Prof. Dr. Frank Leymann, IBM
14
HTTP POST: Invoking Code
(C) Prof. Dr. Frank Leymann, IBM
15
A Simple SOAP RPC
( SOAP Message Embedded in HTTP Request)
POST /StockQuote HTTP/1.1
Host: www.stockquoteserver.com
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "Some-URI"
Object Endpoint
<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">
Method name
<symbol>DIS</symbol>
Input parameter
</m:GetLastTradePrice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
16
A simple soap response
( SOAP Message Embedded in HTTP Response)
HTTP/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:GetLastTradePriceResponse xmlns:m="Some-URI">
<Price>34.5</Price>
</m:GetLastTradePriceResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
17
(three) standard aspects of SOAP
Overall message format
A SOAP message is an envelope containing zero
or more headers and exactly one body.
The SOAP encoding rules
defines a serialization mechanism that can be
used to exchange instances of application-defined
datatypes. ( based on XSD)
The SOAP RPC representation
defines a convention that can be used (optional)
to represent remote procedure calls and responses
(if not, message-oriented style)
18
Working example: A soap request
POST /servlet/rpcrouter HTTP/1.1
Host: www.messages.com
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: ""
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
<SOAP-ENV:Body>
<ns1:getMessage xmlns:ns1="urn:NextMessage"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<UserID xsi:type="xsd:string">JDoe</UserID>
<Password xsi:type="xsd:string">0JDOE0</Password>
</ns1:getMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
19
Working example: soap response
HTTP/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:Body>
<ns1:getMessage xmlns:ns1="urn:NextMessage"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:string">Call mom!</return>
</ns1:getMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
20
SOAP Endpoint Reference
85.34.235.95 80
/servlet/rpcrouter/getMessage
POST /servlet/rpcrouter HTTP/1.1
Host: www.messages.com
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: ""
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
<SOAP-ENV:Body>
<ns1:getMessage xmlns:ns1="urn:NextMessage"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<UserID xsi:type="xsd:string">JDoe</UserID>
<Password xsi:type="xsd:string">0JDOE0</Password>
</ns1:getMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
21
SOAP client-server interaction
22
The Apache eXtensible
Interaction System (AXIS)
 A very flexible SOAP engine from Apache
- Open and pluggable architecture
- Design to cope with various deployment configuration
• From very simplistic to highly sophisticated configurations
 The Java Web Services facility (JWS)
- Drop-in development
• Simplest and quickest way to deploy a Java-base Web Service
• Rename source file from xxx.java to xxx.jws
• Drop xxx.jws into JWS directory
23
APIs de Java
SAAJ (SOAP with Attachment API for Java)
tratar mensajes SOAP como objetos Java
JAX-RPC (Java API for XML based RPC)
WSDL/XML <-> Java
API para cliente: WSDL, Invocación, proxy dinámico
JWSDL
acceso a descripciones WSDL
JAXR (Java API for XML registries)
acceso a registros de servicios Web
...
24
Creación de un Servicio Web
Utilizar JWS
- Con limitaciones (no package, ...)
WSDD (Web Service Deployment Descriptor)
25
Creación de un cliente
1. Acceder a WSDL
http: ....Calculator.jws?wsdl
-> almacenar Calculator.wsdl
2. Generar stubs
java org.apache.axis.wsdl.WSDL2Java –p Calculator Calculator.wsdl
3.
4.
5.
6.
Clases generadas ls Calculator/ *.java
Compilar javac Calculator/ *.java
Compilar cliente javac ClienteCalculator.java
Ejecutar cliente java ClienteCalculator
26
What is WSDL?
SOAP
specifies the communication between a requester and
a provider
WSDL
describes the services offered by the provider (an
“endpoint”)
and might be used as a recipe to generate the proper SOAP
messages to access the services.
• WSDL describes network services by using an XML grammar.
• A WSDL document has a role similar to an IDL file in CORBA
or the Remote Interface in a Java RMI implementation.
27
Complete picture of distributed
applications (using WS)
28
WSDL
service
1-M
port
1-1
binding
1-1
1-M
port types
1-M
operation
message
1-M
types
29
Types: xSchema definition of
data
Service
Port
Binding
Port Types
Operations
Messages
Types
<types>
<schema
targetNamespace="http://example.com/stockquote.xsd"
xmlns="http://www.w3.org/2000/10/XMLSchema">
<element name="TradePriceRequest">
<complexType>
<element name="tickerSymbol" type="string"/>
</complexType>
</element>
<element name="TradePrice">
<complexType>
<element name="price" type="float"/>
</complexType>
</element>
</schema>
</types>
30
Messages: meaningful collections
of Types
Service
Port
Binding
Port Types
Operations
Messages
Types
<message name="GetLastTradePriceInput">
<part name="body" element="xsd1:TradePriceRequest"/>
</message>
<message name="GetLastTradePriceOutput">
<part name="body" element="xsd1:TradePrice"/>
</message>
31
Operations: available Methods
Service
Port
Binding
Port Types
Operations
Messages
Types
<operation name="GetLastTradePrice">
<soap:operation
soapAction="http://example.com/GetLastTradePrice"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
32
Port Types: XML in/out for
specific methods
Service
Maps Operations to Messages
Port
Binding
Port Types
Operations
<portType name="StockQuotePortType">
<operation name="GetLastTradePrice">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</portType>
Messages
Types
33
Binding: Maps Protocols to Methods
(Http, etc.)
Service
Port
Binding
Port Types
Operations
Messages
<binding name="StockQuoteSoapBinding“
type="tns:StockQuotePortType">
<soap:binding style="document“
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetLastTradePrice">
<soap:operation
soapAction="http://example.com/GetLastTradePrice"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
Types
34
Port: Maps URLs to Methods
Service
Port
<port name="StockQuotePort" binding="tns:StockQuoteBinding">
<soap:address location="http://example.com/stockquote"/>
</port>
Binding
Port Types
Operations
Messages
Types
35
Service: Packages ports &
bindings
Service
Port
<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort"
binding="tns:StockQuoteBinding">
<soap:address
location="http://example.com/stockquote"/>
</port>
</service>
Binding
Port Types
Operations
Messages
Types
36
Document structure of WSDL
 <definitions> element: the root of any WSDL
- The name attribute specifies the name of the
Web Service (usually it corresponds to the file
name).
- it contains a set of namespace definitions that
are used throughout the document.
name ='weatherservice‘
- <definitions
...
xmlns='http://schemas.xmlsoap.org/wsdl/'>
……
</definitions>
37
Document structure of WSDL
 <definitions> contains other elements
- elements
• types
• messages
• portType
• bindings
• services
• ...
- Each element within the document may contain a
<documentation> element to provide some human
readable explanation of the element that is specified.
-
In addition, all the elements contain an attribute “name”
serving as an identifier.
38
Document structure of WSDL
 <types> element
- Provide data types definitions
- All data type definitions relevant for sending and
receiving the messages described
- The specification suggests using XML schema
definitions.
<types>
<schema
targetNamespace="http://add.fib.upc.es/symbol.xsd"
xmlns="http://www.w3.org/2000/10/XMLSchema">
<element name="exampleType">
...
</element>
...
</schema>
</types>
39
Document structure of WSDL
<message> element
- specifiy the data that will be communicated
between a requester and a service
- may appear multiple times and consists of a name
and one or more <part> elements.
- The parts specify the contents of the message.
<message name='Weather.GetTemperature'>
<part name='zipcode' type='xsd:string'/>
<part name='celsius' type='xsd:boolean'/>
</message>
<message name='Weather.GetTemperatureResponse'>
<part name='Result' type='xsd:float'/>
</message>
40
Document structure of WSDL
<operation> element
- In order to tie the defined messages together as a
request-response pair corresponding to a method
call.
- An operation specifies which message is the input
and which message is the output.
<operation name='GetTemperature'>
<input message='wsdlns:Weather.GetTemperature' />
<output message='wsdlns:Weather.GetTemperatureResponse' />
</operation>
41
Document structure of WSDL
<portType> element
- The collection of all operations (i.e. methods)
exposed by your service
<portType name='WeatherSoapPort'>
<operation name='GetTemperature'>
<input message='wsdlns:Weather.GetTemperature' />
<output message='wsdlns:Weather.GetTemperatureResponse' />
</operation>
<!-- other operations would go here -->
</portType>
42
Document structure of WSDL
<binding> element
- to bind the operation to the SOAP protocol.
The elements presented so far described our operation in a
generic way (Nothing has been said about a concrete
implementation).
- Next to a name attribute it contains a type
attribute that references a portType and provides
predefined binding for protocols such as SOAP,
HTTP, and MIME.
<binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort' >
….
</binding>
43
Document structure of WSDL
<binding> element (cont)
- Binding to SOAP
Inside the <binding> element you have a WSDL SOAP extension
element called <soap:binding> which is used to specify the
transport protocol you’re using (SOAP can be used over HTTP,
SMTP, or possibly any other transport) and the style of request (rpc
and document are the two styles).
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http' />
44
Document structure of WSDL
<binding> element (cont)
• Then for each operation that this service exposes, you specify
the value of the SOAPAction that is used for the HTTP header
of SOAP message
<binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort' >
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http' />
<operation name='GetTemperature' >
<soap:operation soapAction='http://tempuri.org/action/Weather.GetTemperature' />
....
</operation>
</binding>
45
Document structure of WSDL
<binding> element (cont)
• There has to be at least one binding for every portType.
• In order to specify how the input and output messages of this
operation are encoded, there is an operation element having three
subelements: input, output, and fault. Each operation corresponds to
an operation in the portType element.
<binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort' >
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
<operation name='GetTemperature' >
<soap:operation soapAction='http://tempuri.org/action/Weather.GetTemperature' />
<input>
<soap:body use='encoded' namespace='http://tempuri.org/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='http://tempuri.org/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
46
Document structure of WSDL
<service> and <port> element
- A service is a set of related ports.
- The binding is specified within the port element.
- In order to bind to the SOAP protocol a
<soap:address> is defined.
• It contains a name and a location that defines an
address of the same type as the transport specified in
the soap:binding element. That means that we have to
define a HTTP address.
 See the Web Service Example
47
WSDL Structure Overview
 portType
- Abstract definition of a
service (set of
operations)
Service
Port
Port
Binding
Binding
(e.g. http://host/svc)
 Multiple bindings per
portType:
- How to access it
 Ports
- Where to access it
(e.g. SOAP)
portType
operation(s)
inMesage
outMessage
Abstract interface
48
WSDL Example:
float Weather::GetTemperature(String zipCode, bool celsius)
{
if (celsius)
return 21.7;
else
return 71.06;
}
49
WSDL Example: Defining Services
 You can think of the class as the Web service and the
GetTemperature method as an operation on that service. To
describe this service, you use the WSDL <service> element.
<definitions name ='weatherservice‘
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<service name='WeatherService' >
……
</service>
</definitions>
50
WSDL Example: Defining Services
(cont.)
 Each service is defined using a service element. Inside the
service element, you specify the different ports on which this
service is accessible.
 The port definition would be like this:
<port name='WeatherSoapPort' binding='wsdlns:WeatherSoapBinding' >
<soap:address
location='http://localhost/demos/wsdl/devxpert/weatherservice.asp' />
</port>
51
WSDL Example: Defining Services
(cont.)
 A Web service does not have to be exposed using SOAP. For
example, if your Web service is exposed via HTTP GET, the
port element would contain an <http:address/> element similar to
this:
<http:address
location="http://localhost/demos/wsdl/devxpert/weatherGET.asp"/>
 A Web service may be accessible on many ports. For example, you
might make your service available via SOAP and HTTP GET and
possibly even via SMTP. For this Web service, you would have three
ports each one with a different name.
52
WSDL Example: What’s Your
Message? (cont.)
 To use Web services in a remote procedure call (RPC) model, there are
two messages you must describe.
 To describe the message structures, you use the WSDL <message>
element. Each <message> contains zero or more <part> elements. A
<part> corresponds to a parameter or a return value in the RPC call.
<message name='Weather.GetTemperature'>
<part name='zipcode' type='xsd:string'/>
<part name='celsius' type='xsd:boolean'/>
</message>
<message name='Weather.GetTemperatureResponse'>
<part name='Result' type='xsd:float'/>
</message>
53
WSDL Example: Port Types and
Operations
 An operation specifies which message is the input and which
message is the output like this:
<operation name='GetTemperature'>
<input message='wsdlns:Weather.GetTemperature' />
<output message='wsdlns:Weather.GetTemperatureResponse' />
</operation>
54
WSDL Example: Port Types and
Operations (cont.)
 The collection of all operations (i.e. methods) exposed by your
service is called a portType and is defined using the WSDL
<portType> element like this:
<portType name='WeatherSoapPort'>
<operation name='GetTemperature'>
<input message='wsdlns:Weather.GetTemperature' />
<output message='wsdlns:Weather.GetTemperatureResponse' />
</operation>
<!-- other operations would go here -->
</portType>
55
WSDL Example: Binding It All
Together
 We are now making a transition from abstract data types,
messages, and operations to concrete physical representation of
messages on the wire. To define the concrete aspects of
operations, you use the WSDL <binding> element:
<binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort' >
….
</binding>
56
WSDL Example: Binding It All
Together (cont.)
 Inside the <binding> element you have a WSDL SOAP
extension element called <soap:binding> which is used to
specify the transport protocol you’re using (SOAP can be used
over HTTP, SMTP, or possibly any other transport) and the style
of request (rpc and document are the two styles). For example:
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http' />
57
WSDL Example: Binding It All
Together (cont.)
 Then for each operation that this service exposes, we specify the
value of the SOAPAction HTTP header :
<binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort' >
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http' />
<operation name='GetTemperature' >
<soap:operation
soapAction='http://tempuri.org/action/Weather.GetTemperature' />
....
</operation>
</binding>
58
SOAP client-server interaction
(rep)
59
WSDL Example: Binding It All
Together (cont.)
 Finally, we must specify how the input and output messages of this
operation are encoded, the complete binding looks like this:
<binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort' >
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
<operation name='GetTemperature' >
<soap:operation soapAction='http://tempuri.org/action/Weather.GetTemperature' />
<input>
<soap:body use='encoded' namespace='http://tempuri.org/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='http://tempuri.org/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
60
What is UDDI?
Universal Description, Discovery, and
Integration (UDDI) is a standard designed to
provide a searchable directory of
businesses and their Web Services.
Thus, it represents the service broker that
enables service requesters to find a suitable
service provider.
61
Complete picture of distributed
applications (using WS)
62
What is UDDI?
 To get access to the UDDI services, the UDDI
directory exposes a set of APIs in the form of a
SOAP-based Web Service.
 UDDI APIs
- Publication API - Authenticated set of operations
that allow organizations to publish businesses,
services, service type specifications
- Inquiry API - Non authenticated public set of
operations that allows users to extract
information out of the UDDI registry.
63
What is UDDI?
 UDDI classifies businesses and services according to standard
taxonomies
 Why Classification ?
- Searches based on keywords alone, could return a large
set of hits for a particular search
- Classification of services and businesses allows to perform
better searches
 Registry Data
•
•
•
•
White Pages
Yellow Pages
Green Pages
ServiceType Registrations
64
What is UDDI?
(In many ways UDDI is designed like a phone book)
 White
White Pages
Pages
- contains business name, text description, contact info and other related
info.
 Yellow Pages
- contains classification information about the business entity and types of
the services the entity offers.
Searches can be performed to locate businesses which service a particular
industry or product category, or that are located within a specific geographic
region.
Green Pages
Pages
 Green
- contains information about how to invoke the offered services.
•
If a business entity were to offer its catalog online, its Green
pages entry would have a reference to its catalog URL
65
Web Service Deployment
ServiceProvider
Write
Application
Deploy
Application
As Service
WSDL File
Generation and
Registration
1
WSDL
SOAP Request
Remote UDDI
Web Service
Registry
Start
Listener
66
Dynamic Service Invocation
Service Requestor
Automated
Web Service
Lookup
Automatic
Service
Selection
2
3
SOAP Request
WSDL(s)
Remote UDDI
Web Service
(Registry)
(SOAP Response)
1
Dynamic
Client Code
Generation
Web Service
Invocation
Remote
Web service
4
SOAP Request
5
SOAP Response
Publish Web
Service
67
Business registry nodes
-
http://uddi.microsoft.com
http://uddi.ibm.com
http://uddi.<companyname>.com
...
68
Web Services Performance
New technologies are often marketed with
grand promises to solve business problems,
but ... PERFORMANCE?
Performance criteria
- simultaneous requests,
- latency in responding to requests,
- levels of operational degradation due to increases
in transaction loads.
- ...
69
Web Services Performance
Web service component stack
70
Web Services Performance
Impact of parsing and marshalling
(source: http://www-106.ibm.com/developerworks/library/ws-best9)
71