Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
1
Web Services
Lecture 10
2
Outline
• Overview of Web Services• SOAP (messaging)• WSDL (service description)• UDDI (registry)
3
A bit of buzz (1)• “By 2006, Web services will take hold as a
competitive differentiator in business relationshipsand product innovation. Enterprises that want toremain competitive will need to use Web services toprovide commonly requested data to their partners. Itis imperative that enterprises develop a strategy forhow to use Web services to develop products,including hard goods, digital goods and services.”
Gartner Research, November 2003
4
A bit of buzz (2)• Yankee Group, Nov. 2004 survey (437
entreprises)– 48% have already deployed Web Services– 39% will deploy Web Services within one year– 71% will increase spending on Web Services in
2005
• Jeff Bezos (CEO Amazon), Tech. Review01/2005– “Web 1.0 was making the Internet for people;
Web 2.0 is making the Internet better forcomputers”
5
What is a Web Service?• A web service is a network accessible
interface to application programs, built usingstandard Internet technologies.
• Clients of web services do NOT need toknow how it is implemented.
Application
client
Application
programNetwork Web
Service
6
• A Web Service is a URL-addressable software resource thatperforms functions (or a function).
• "Web services are a new breed of Web application. They areself-contained, self-describing, modular applications that can bepublished, located, and invoked across the Web. Web servicesperform functions, which can be anything from simple requeststo complicated business processes. … Once a Web service isdeployed, other applications (and other Web services) candiscover and invoke the deployed service.” IBM web servicetutorial
Web Services: SomeDefinitions
7
Web Evolution
Program theWeb
Browse the WebCreate the WebOutcome
Web ServicesWeb PagesE-Mail, FTP…Applications
ProgrammabilityPresentationConnectivityPurpose
XMLHTMLTCP/IPTechnology
8
Web Service Architecture
Service provider
Service broker Service requestor
publish(WSDL)
find(UDDI)
bind(SOAP)
"server"
"client""naming service"
9
Web Service Stack
• A set of standards for implementing webservices
Transport: HTTP, SMTP, FTTP, …
Messaging: SOAP
Service Description: WSDL
Publication and Discovery: UDDI
extends HTTP
extends HTML
extends URI
10
Basic Web Service UsageScenario
Web Service Repository
(UDDI)
publish webservice
Web ServiceProvider
1 registerWSDL file
(manually)
(manual) web service lookup
2 http get
3 WSDL file
write clientapplication
deploy clientapplication
4 SOAP request
5 SOAP response
11
Web Services Implementation
• Application Server (web service-enabled)– provides implementation of services and exposes it through WSDL/SOAP– implementation in Java, as EJB, as .NET (C#) etc.
• SOAP server– implements the SOAP protocol
• HTTP server– standard Web server
• SOAP client– implements the SOAP protocol on the client site
Requestor(SOAP client)
Web Service Provider(endpoint)
HTTP server
SOAP server
application server
SOAP messages
(http transport)
12
Down to earth example:Amazon Web Services
• www.amazon.com/gp/aws/landing.html• Exposes world’s largest product database through
Web Services– Counterintuitive strategy? (cf. Google)
• Idea: let others figure out how to sell products for us– Associates program enables Web sites to link to
Amazon.com and earn referral fees• By November 2004: 65,000 developers• Some interesting examples:
– www.grokker.com– www.monsoonretail.com
13
• Lightweight messaging framework based on XML• Supports simple messaging and RPC (remote procedure calls)• SOAP consists of
– Envelope construct: defines the overall structure of messages– Encoding rules: define the serialization of application data types– SOAP RPC: defines representation of remote procedure calls and
responses– Binding framework: binding to protocols such as HTTP, SMTP– Fault handling
• SOAP supports advanced message processing:– forwarding intermediaries: route messages based on the
semantics of message– active intermediaries: do additional processing before forwarding
messages, may modify message
2. SOAP –Simple Object Access Protocol
14
Client-Server Interaction
Client Server
Proxy
15
SOAP Message• SOAP messages consist of
– Envelope: top element of XML message (required)– Header: general information on message such as security
(optional)– Body: data exchanged (required)
• Header– elements are application-specific– may be processed and changed
by intermediaries or recipient• Body
– elements are application-specific– processed by recipient only
envelope
header
body
16
Skeleton SOAP Message<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Header> ... ...</soap:Header>
<soap:Body> ... ... <soap:Fault> ... ... </soap:Fault></soap:Body>
</soap:Envelope>
17
Java Classpublic class TravelAgency {public int reservation(String date),public int passenger(String name),
public int itinery(String departure, String arriving, String departureDate),
public int returnFlight(String departing, String arriving, String departureDate)
}
18
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope"> <env:Header> <m:reservation xmlns:m=http://travelcompany.example.org/reservation env:role=http://www.w3.org/2002/12/soap-envelope/role/next env:mustUnderstand="true"> <m:dateAndTime>2001-11-29T13:20:00.000-05:00</m:dateAndTime> </m:reservation> <n:passenger xmlns:n=http://mycompany.example.com/employees env:role=http://www.w3.org/2002/12/soap-envelope/role/next env:mustUnderstand="true"> <n:name>Åke Jógvan Øyvind</n:name> </n:passenger> </env:Header> <env:Body> <p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel"> <p:departure> <p:departing>New York</p:departing> <p:arriving>Los Angeles</p:arriving> <p:departureDate>2001-12-14</p:departureDate> </p:departure> <p:returnFlight> <p:departing>Los Angeles</p:departing> <p:arriving>New York</p:arriving> <p:departureDate>2001-12-20</p:departureDate> </p:returnFlight> </p:itinerary> </env:Body></env:Envelope>
Example: SOAP MessageEnvelope
Header
Body
SOAP attributes
SOAP attributes
19
Conversational MessageExchanges in SOAP
proposeditinerary
alternatives
choice
travel agency customer
20
SOAP RPC• Encapsulate RPC into SOAP messages
– procedure name and arguments– response (return value)– processing instructions (transactional RPC!)
• Example: Request message<?xml version='1.0' ?>
<env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope" ><env:Header> <t:transaction xmlns:t="http://thirdparty.example.org/transaction"
env:encodingStyle="http://example.com/encoding" env:mustUnderstand="true" >5</t:transaction>
</env:Header><env:Body> <m:chargeReservationRequest env:encodingStyle="http://www.w3.org/2002/12/soap-encoding" xmlns:m="http://travelcompany.example.org/"> <m:reservation xmlns:m="http://travelcompany.example.org/reservation"> <m:code>FT35ZBQ</m:code> </m:reservation> <o:creditCard xmlns:o="http://mycompany.example.com/financial"> <n:name xmlns:n="http://mycompany.example.com/employees"> Åke Jógvan Øyvind </n:name> <o:number>123456789099999</o:number> <o:expiration>2005-02</o:expiration> </o:creditCard> </m:chargeReservationRequest></env:Body></env:Envelope>
transaction information
TID method invocation
parameter 1
parameter 2
21
SOAP RPC• Example cntd.: Response message
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope" ><env:Header> <t:transaction xmlns:t=http://thirdparty.example.org/transaction env:encodingStyle=http://example.com/encoding env:mustUnderstand="true">5</t:transaction></env:Header><env:Body> <m:chargeReservationResponse env:encodingStyle=http://www.w3.org/2002/12/soap-encoding xmlns:m="http://travelcompany.example.org/"> <m:code>FT35ZBQ</m:code> <m:viewAt> http://travelcompany.example.org/reservations?code=FT35ZBQ </m:viewAt> </m:chargeReservationResponse></env:Body></env:Envelope>
method result
output parameters
22
SOAP Processing Model (1)• Elements in the Header may carry SOAP-specific attributes
controlling the message processing– attributes from namespacehttp://www.w3.org/2002/12/soap-envelope
– role, mustUnderstand, relay, encodingStyle• "role" attribute
– if processing node matches role in header, it must process theheader
– special role "next": receiving node must be capable of processingheader
– special role "ultimateRceiver: receiving node must be capable ofprocessing body
• "mustUnderstand" attribute– processing of header information is mandatory
23
SOAP Processing Model (2)• "relay" attribute
– header block must be relayed if it is not processed• "encodingStyle" attribute
– Indicates the encoding rules used to serializeparts of a SOAP messages
• "http://www.w3.org/2003/05/soap-encoding"– Base64– date– hexBinary …
• "http://example.org/encoding/"• "http://www.w3.org/2003/05/soap-envelope/encoding/none"
24
The Fault element• Carries an error message• If present, must appear as a child of <Body>• Must only appear once• Has the following sub-elements:
Holds application specific error informationrelated to the Body element
<detail>
Information about who caused the fault tohappen
<faultactor>
A human readable explanation of the fault<faultstring>
A code for identifying the fault(VersionMismatch, MustUnderstand, Client, Server)
<faultcode>
DescriptionSub Element
25
Protocol Binding• Bindings to different protocols possible: HTTP, SMTP• Different HTTP bindings: HTTP POST, HTTP GET
– standard HTTP POST for request-response
POST /Reservations?code=FT35ZBQ HTTP/1.1Host: travelcompany.example.orgContent-Type: application/soap+xml; charset="utf-8"Content-Length: nnnn
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope"> …SOAP request message…</env:Envelope>
HTTP/1.1 200 OKContent-Type: application/soap+xml; charset="utf-8"Content-Length: nnnn
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope">… SOAP response message …</env:Envelope>
HTTP POSTrequest
HTTP response
26
• Description of Web services in XML format– abstract description of operations and their parameters
(messages)– binding to a concrete network protocol (e.g. SOAP)– specification of endpoints for accessing the service
• Structure of a WSDL document Types: structureof messages
Messages: usedby operations
(abstract)Operations
PortType: operations supported by service
Binding: concrete protocol
Service: collection of related ports
Port: Binding and a network address
(protocol)Operations
abstract
concrete
3. WSDL – Web ServiceDescription Language
27
Overview of Defining WSDLServices
1. Define in XML Schema the message types used when invokingthe service: MT1, MT2 etc.
2. Define (named) messages by using these types, e.g.• message m1 has type MT1• message m2 has type MT2 etc.
3. Define Services that consist of one or more operations; eachoperation is implemented by the exchange of messages• service S offers operation O1; for executing O1 first send a request
message m1, then a response message m2 is returned4. Define a Binding B to a specific protocol, e.g. SOAP
• service S is implemented in SOAP; the SOAP messages areconstructed from the abstract messages m1 and m2 by, e.g.inlining the message as body of SOAP messages
5. Service S is provided with binding B at the following URI's(called ports)
28
WSDL Example<?xml version="1.0">
<definitions name="StockQuote><types>
<schema>definition of types in XML Schema …………
</schema></types><message name="GetTradePriceInput">
<part name=”bid" type="xsd:string"/></message><portType name="StockQuotePortType">
<operation name="GetLastTradePrice">definition of an operation ………
</operation></portType><binding name="StockQuoteSoapBinding">
definition of a binding ………</binding><service name="StockQuoteService">
<port name="StockQuotePort">definition of a port ………
</port></service></definitions>
1
2
3
4
5
67
29
WSDL Details
Aggregation of ports that belong together<service>
Address for the binding<port>
Definitions of protocols etc.<binding>
Set of operations supported by a service<portType>
Defines all messages<message>
Data type definitions<type>Root element<definition>1
2
34
5
6
7
30
C++ Example: TaskServerint ns__getTask(std::string hostname,
std::string &task);
int ns__finished(std::string ftask, std::string &task);
int ns__error(std::string ftask,. std::string &task);
31
<?xml version="1.0" encoding="UTF-8"?><definitions name="WGTaskServer" targetNamespace="http://ludwig-sun2.unil.ch/~hstockin/WGTaskServer.wsdl" xmlns:tns="http://ludwig-sun2.unil.ch/~hstockin/WGTaskServer.wsdl" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="urn:wgTaskServer" xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/" xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:wgTaskServer" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="urn:wgTaskServer" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> </schema>
</types>
1
2
32
<message name="getTaskRequest"> <part name="hostname" type="xsd:string"/></message>
<message name="getTaskResponse"> <part name="task" type="xsd:string"/></message>
<message name="finishedRequest"> <part name="ftask" type="xsd:string"/></message>
<message name="finishedResponse"> <part name="task" type="xsd:string"/></message>
<message name="errorRequest"> <part name="ftask" type="xsd:string"/></message>
<message name="errorResponse"> <part name="task" type="xsd:string"/></message>
3
int ns__getTask(std::string hostname,
std::string &task);
int ns__finished(std::string ftask,
std::string &task);
int ns__error(std::string ftask,.std::string &task);
33
<portType name="WGTaskServerPortType"> <operation name="getTask"> <documentation>Service definition of function ns__getTask </documentation> <input message="tns:getTaskRequest"/> <output message="tns:getTaskResponse"/> </operation> <operation name="finished"> <documentation>Service definition of function ns__finished </documentation> <input message="tns:finishedRequest"/> <output message="tns:finishedResponse"/> </operation> <operation name="error"> <documentation>Service definition of function ns__error </documentation> <input message="tns:errorRequest"/> <output message="tns:errorResponse"/> </operation></portType>
4
34
<binding name="WGTaskServer" type="tns:WGTaskServerPortType"> <SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="getTask"> <SOAP:operation style="rpc" soapAction=""/> <input> <SOAP:body use="encoded" namespace="urn:wgTaskServer" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <SOAP:body use="encoded" namespace="urn:wgTaskServer" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> <operation name="finished"> <SOAP:operation style="rpc" soapAction=""/> <input> <SOAP:body use="encoded" namespace="urn:wgTaskServer" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <SOAP:body use="encoded" namespace="urn:wgTaskServer" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> <operation name="error"> <SOAP:operation style="rpc" soapAction=""/> <input> <SOAP:body use="encoded" namespace="urn:wgTaskServer" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <SOAP:body use="encoded" namespace="urn:wgTaskServer" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation></binding>
5
35
<service name="WGTaskServer"> <documentation>gSOAP 2.7.6e generated service definition </documentation> <port name="WGTaskServer" binding="tns:WGTaskServer"> <SOAP:address location="http://localhost:8085"/> </port></service>
</definitions>
6
7
36
PortTypes (1)
• WSDL supports 4 message patterns that anendpoint (=service provider!) can support for anoperation– one-way: message is sent to service provider
without expecting response– request-response: request is sent to service
provider expecting response– solicit-response: provider sends a message
and expects response– notification: message is sent by service
provider
37
PortTypes (2)• Message patterns are distinguished by the use of input/output
elements– one way:
<wsdl:definitions .... > <wsdl:portType .... > * <wsdl:operation name=”doSomething"> <wsdl:input name=”doSomething"? message=”qname"/> </wsdl:operation> </wsdl:portType ></wsdl:definitions>
– request/response:<wsdl:definitions .... > <wsdl:portType .... > * <wsdl:operation name=”doSomething" parameterOrder="nmtokens"> <wsdl:input name=”doSomething"? message="qname"/> <wsdl:output name=”doSomething"? message="qname"/> <wsdl:fault name=”doSomething" message="qname"/>* </wsdl:operation </wsdl:portType ></wsdl:definitions>
38
Data Types
• Typically, XML Schema are standarddata types (string, int, etc.)
<wsdl:types> <xsd:schema targetNamespace=“http://example.com“ xmlns:xsd=„http://www.w3.org/2000/10/XMLSchema“> <xsd:element name=“PositionRequest“> <xsd:complexType> <xsd:sequence> <xsd:element name=“zipCode“ type=“string“/> </xsd:sequence> </xsd:complexType> </xsd:element></wsdl:types>
39
• Standard for describing, publishing and finding web services– Still evolving– Use XML-based description files for services
• Main components– White pages: basic contact information about an organization– Yellow pages: classification of organization based on industrial
categorization– Green pages: technical description of services offered by
registered organizations• Access to UDDI Registry
– Standard UDDI API (accessible via SOAP)– Web browser
• Data Structures (XML)– Business entity: general information + business services– Business services: business level description + binding templates– Binding templates: access point + tModel (service types)– tModel: abstract definition of a web service
4. UDDI – Universal DescriptionDiscovery and Integration
40
Registering a WSDL Service in UDDI1. Register a business2. Register the abstract service definition (tModel)3. Register the service implementation definition
(BusinessService)• Step 1: Register a business
(see demo at https://uddi.ibm.com/testregistry/registry.html/)
41
Step 2: Registering an AbstractWSDL Service Definition
<?xml version="1.0"><definitions name="StockQuote> <types>
<schema> definition of types
</schema></types> <message name="GetTradePriceInput">
definition of a message</message> <portType name="StockQuotePortType">
<operation name="GetLastTradePrice">definition of an operation ……… </operation>
</portType> <binding name="StockQuoteSoapBinding"> definition of a binding ………</binding><service name="StockQuoteService">
<port name="StockQuotePort">definition of a port ………</port>
</service></definitions>
<?xml version="1.0"><tModel tModelKey="…">
<name>StockQuote</name> …
<overviewDoc>
<overviewURL> http//…
</overviewURL>
<categoryBag>
<keyedReference tmodelKey="…"
keyName="uddi-org:types"
keyValue="wsdlSpec">
</categoryBag>
</tModel>
service specified in WSDL
42
Step 3: Registering a ServiceImplementation
<?xml version="1.0"><definitions name="StockQuote>
<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>
<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort"
binding="tns:StockQuoteBinding">
<soap:address
location="http://example.com/stockquote"/> </port>
</service>
</definitions>
<?xml version="1.0"><businessEntity businessKey="…">
…
<businessService serviceKey"…"
<name>StockQuote</name>…
<bindingTemplates>
<bindingTemplate>
<accessPoint urlType="http">
http://example.com/stockquote </accessPoint>
<tModelInstanceDetails>
…
<overviewDoc>
<overviewURL>
http://...
</overviewURL>
</overviewDoc>
…
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
</businessService>
</businessEntity>
43
Interface Example (1)
44
Interface Example (2)
45
Interface Example (3)
46
Conclusion• Web services are a very popular way to build
client-server applications• SOAP implementations of different
languages take care of the details– WSDL can be auto-generated from– Language client can be auto-generated from
WSDL• SOAP is a language independent protocol• AXIS is Java’s SOAP implementation
– http://ws.apache.org/axis/index.html
47
References
• Standard documents– http://www.w3.org/2002/ws/– http://www.w3.org/TR/2002/CR-soap12-
part0-20021219/ (SOAP primer)– http://www.w3.org/TR/SOAP/– http://www.w3.org/TR/wsdl– http://www.uddi.org