Вы находитесь на странице: 1из 77

Web Services and Their

Protocol Stack
Juanzi Li
Department of Computer Science and Technology
Tsinghua University
Mar. 2007

1
Outline
• The Model of SOA
• Overview of Web Services
• XML and XML Schema
• The Communication Protocol
• Web Services Description
• Web Services Flow Description
• Web Services Publication and Discovery

2
The Model of SOA

3
SOA Model
• As a distributed computing architecture, Web Services
are the most important implementation for SOA.
• SOA Model is Web Services Concept Architecture.

4
Concept in SOA Model
• Role
– Services Provider
– Services Requestor
– Services Registry
• Operation
– Publish
– Find
– Bind
• Key Component
– Services
– Services Description

5
Core Standards in SOA Model
• Some Standards
– Web Services Description Language (WSDL)
– Universal Description, Discovery and Integration (UDDI)
– Simple Object Access Protocol (SOAP)
– Web Service Flow Language
– ……

6
Process in SOA Development

Business Component Analysis

Services Identification

Services Specification

Component Identification

Component Specification

Services Realization Decision

SOA Implementation

7
The Level Model of SOA Development
Services Consumer

Business Process

Integration Architecture

Qos Security Management


Services
Services Provider

Components

Existing Application Resources

8
Process vs Level Model

9
Relationship Between SOA and Web
Services
• Based on open standard and flexible implementation, Web services
is natively applicable to SOA implementation.
• The Relationships between Web services and SOA are:
– Web services provide an open standard and machine-readable model
(WSDL) for creating explicit, implementation-independent descriptions
of service interfaces.

– Web services provide communication mechanisms that are location-


transparent and interoperable.

– Web services are evolving through BPEL4WS, document-style SOAP, and


WSDL, and emerging technologies such as WS-ResourceFramework to
support the technical implementation of well-designed services that
encapsulate and model reusable function in a flexible manner.
10
Overview of Web Services

11
Web Services
• The Web: Flexible human-machine interaction
• Web Services: Web services are a recent set of technology
specifications that leverage existing proven open standards such as
XML, URL, and HTTP to provide a new system-to-system
communication standard.
• Working Definition: Network-resident software Services
accessible via standardized protocols
– Simple Object Access Protocol (SOAP): very flexible remote
procedure call
• Lots of interest in trade press, academic community, standards
bodies, . . .
• Applications in e-commerce, telecom, science, GRID,
government, education, . . .

12
Categories of Web Services
• Business-Oriented Web Services
– ERP,CRM ,
– Application system integration
• Consumer-Oriented Web Services
– B2C website, across multi B2C systems
• Device-Oriented Web Services
– Support the services across different kinds of services.
E.g weather report, email service
• System-Oriented Web Services
– Authentication
– Monitoring
– QoS

13
The Processes of Web Services
Simplify and/or automate web Services
• Discovery
– What properties should be described?
– How to efficiently query against them?
• Composition
– Specifying goals of a composition
– Specifying constraints on a composition
– Building a composition
– Analysis of compositions
• Invocation
– Keeping enactments separated
– Providing transactional guarantees
• Monitoring
– How to track enactments
– Recovering from failed enactments
14
Web Services Standard Stack
Web Services Web Services
Security: Transaction:
XML-Encryption WS-Coordination
Web Services
XML-Signature WS-Transaction Publishing and
composition:
WS-Security WS-AtomicTransaction discovery:
WSFL,BPEL4WS WS- WS-BusinessActivity UDDI,
WS-CDL SecureConversation Web Services WSIL
WS-CAF WS- Management: , WS-Discovery
SecurityPolicy WSDM, WS-Manageability
WS-Trust SPML, WS-Provisioning

Services Description Layer: WSDL, WSCL, WSCI,WS-MetadataExchange, W

XML messaging layer: SOAP , WS-Addressing, WS-Notification, WS-Eventing


WS-Enumeration, WS-MessageDelivery, WS-Reliability,WS Reliable Messaging
WS-Resources WS-Transfer

Transport layer: HTTP, SMTP, FTP, etc.


15
Web Service Core Standards

Behavior BPEL

Interface WSDL

IBM WebSphere

Microsoft .Net
Message SOAP

Sun J2EE
Type XML Schema

Data XML

Web Service Standards Implementation Platforms

16
XML and XML Schema

17
The structure of XML
• Tag: label for a section of data
• Element and Subelement: section of data beginning with
<tagname> and ending with matching </tagname>
Elements must be properly nested

– Proper nesting
• <account> … <balance> …. </balance> </account>
– Improper nesting
• <account> … <balance> …. </account> </balance>
– Formally: every start tag must have a unique matching end
tag, that is in the context of the same parent element.

18
The structure of XML
– Every document must have a single top-level element
<bank>
<customer>
<name> Hayes </name>
<street> Main </street>
<city> Harrison </city>
<account>
<account-number> A-102 </account-number>
<branch-name>Perryridge </branch-name>
<balance> 400 </balance>
</account>
<account>

</account>
</customer>
.
. Top level element
</bank>

19
The structure of XML
• Attribute
– Elements can have attributes
<account acct-type = “checking” >
<account-number> A-102 </account-number>
<branch-name> Perryridge </branch-name>
<balance> 400 </balance>
</account>
– Attributes are specified by name=value pairs inside the
starting tag of an element
– An element may have several attributes, but each attribute
name can only occur once
• <account acct-type = “checking” monthly-fee=“5”>

20
The structure of XML
• Differences between element and attribute
attributes cannot be nested
<customer name=Hayes street=Main city=Harrison>
<account>
<account-number> A-102 </account-number>
<branch-name> Perryridge </branch-name>
<balance> 400 </balance>
</account>
<account>

</account>
</customer>

21
The structure of XML

• Well-Formed XML Documents


– There is only one outermost element in the document
(called the root element)
– Each element contains an opening and a
corresponding closing tag
– Tags can not overlap, as in
<author><name>LeeHong</author></name>
– Attributes within an element have unique names
– Element and tag names must be permissible

22
The structure of XML
• The Tree Model of XML Documents
– There is exactly one root
– There are no cycles
– Each node, other than the root, has exactly
one parent
– Each node has a label. Element or attribute
– The order of elements is important

23
24
Namespace
• XML data has to be exchanged between organizations
• Same tag name may have different meanings in
different organizations, causing confusion on
exchanged documents
• Specifying a unique string as an element name avoids
confusion
• Better solution: use unique-name:element-name
• Avoid using long unique names all over document by
using XML Namespaces

25
Namespace
<Schema name="mySchema"
        xmlns="urn:schemas-microsoft-com:xml-data"
        xmlns:dt="urn:schemas-microsoft-com:datatypes"

xmlns:myNS=http://www.xml_step_by_step.edu\ns.xml
>

Three namespaces:
schema namespace
datatype namespace
myNS namespace

26
XML Schema
• Database schemas constrain what information can be stored, and
the data types of stored values

• schemas are very important for XML data exchange


– Otherwise, a site cannot automatically interpret data received
from another site

• Two mechanisms for specifying XML schema


– Document Type Definition (DTD)
– XML Schema

27
XML Schema
• XML Schema Supports
– Typing of values
• E.g. integer, string, etc
• Also, constraints on min/max values
– User defined types
– Is itself specified in XML syntax, unlike DTDs
• More standard representation, but verbose
– Is integrated with namespaces (reuse and refine)
– Many more features
• List types, uniqueness and foreign key constraints,
inheritance ..
28
<xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema>
<xsd:element name=“bank” type=“BankType”/>
<xsd:element name=“account”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“account-number” type=“xsd:string”/>
<xsd:element name=“branch-name” type=“xsd:string”/>
<xsd:element name=“balance” type=“xsd:decimal”/>
</xsd:squence>
</xsd:complexType>
</xsd:element>
….. definitions of customer and depositor ….
<xsd:complexType name=“BankType”>
<xsd:squence>
<xsd:element ref=“account” minOccurs=“0” maxOccurs=“unbounded”/>
<xsd:element ref=“customer” minOccurs=“0” maxOccurs=“unbounded”/>
<xsd:element ref=“depositor” minOccurs=“0” maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

29
XML Schema

• Element Types
<element name=". . ."/> with possible attributes:
– ‘ type’ attribute
define the element type of this element: type=". . ." (more on
types later)
– cardinality constraints:
• minOccurs="x", where x may be any natural number
(including zero)
• maxOccurs="x", where x may be any natural number
(including zero) or unbounded

30
XML Schema
<element name="email"/>
<element name="head" minOccurs="1"
maxOccurs="1"/>
<element name="to" minOccurs="1"/>

31
XML Schema
• Attribute Types
<attribute name=". . ."/> with possible
attributes
– type=". . ."
– use="x", corresponds to #OPTIONAL and
#IMPLIED in DTDs
– use="x" value=". . .", where x may be
default or fixed

32
XML Schema
<attribute name="id" type="ID"
use="required"/>

<attribute name="speaks"
type="LanguageType" use="default“
value="en"/>

33
XML Schema

• Data Types
– Numerical data types, including integer, Short,
Byte, Long, Float,Decimal
– String data types, including string, ID, IDREF,
CDATA, Language
– Date and time data types
• user-defined data types
– simple data types and complex data types

34
XML Schema
• Complex data type and extension data type
– defined from already existing data types by defining some
attributes (if any) and using sequence, all and choice.

<complexType name="lecturerType">
<sequence>
<element name="firstname" type="string"
minOccurs="0" maxOccurs="unbounded"/>
<element name="lastname" type="string"/>
</sequence>
<attribute name="title" type="string" use="optional"/>
</complexType>
35
XML Schema

• <element name=“lecture” type=“lectureType”>

<lecture title=“associate professor”>


<firstname>gang</firstname>
<lastname>Huang</lastname>
</lecture>

36
XML Schema
Data Type Extension: existing data types can be
extended by new elements or attributes

<complexType name="extendedLecturerType">
<extension base="lecturerType">
<sequence>
<element name="email" type="string"
minOccurs="0" maxOccurs="1"/>
</sequence>
<attribute name="rank" type="string" use="required"/>
</extension>
</complexType>
37
XML Schema
• Restriction data type and simple data type
be defined by restricting existing data types
<complexType name="restrictedLecturerType">
<restriction base="lecturerType">
<sequence>
<element name="firstname" type="string"
minOccurs="1" maxOccurs="2"/>
</sequence>
<attribute name="title" type="string" use="required"/>
</restriction>
</complexType>
38
XML schema
• Simple data types can also be defined by
restricting existing data types.
<simpleType name="dayOfMonth">
<restriction base="integer">
<minInclusive value="1"/>
<maxInclusive value="31"/>
</restriction>
</simpleType>

39
The Communication Protocol
(SOAP)

40
Why Simple Object Access
Protocol

• SOAP is an XML messaging protocol that is independent


of any specific transport protocol.
• Light weight replacement for complicated distributed
object technology
• Originally for BizTalk
(Microsoft/UserLand/DevelopMentor )
• Now a W3C standard

• Based on XML

41
SOAP Message Structure
• Envelope contains
– Header
SOAP Envelope
– Body
SOAP Header • Header is optional
Header Block – Out-of-band information
...
such as…
Header Block
• Authentication
information
SOAP Body
• Message routes
Body Block
... • Logging
Body Block • Transaction flow
• Body contains XML body of
RPC call 42
SOAP Example

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-ncoding">
<soap:Body>
<m:GetPrice xmlns:m="http://www.w3schools.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>

43
SOAP Example
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
<m:GetPriceResponse xmlns:m="http://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>

44
Web Services Description
Language

45
Web Services Description Language
(WSDL)
• WSDL is an XML-based interface definition
language that separates function from
implementation, and enables design by contract as
recommended by SOA.

• WSDL defines
– What does Services do – interface
– Access specification – how
– Location of the Services – where

46
Ingredients of WSDL
Supports

Interface Port Type e Operation


o k
Formats & Protocols inv Input & Output
to
w
Ho

Access
specification Binding How to encode
Message
Implements
Provides
Port Services

Endpoints
47
Main Structure of WSDL

<definitions namespace = “http://… ”>


<types> XML schema types </type>
<message> definition of a message </message>
<portType> a set of operations </portType>
<binding> communication protocols </binding>
<Services> a list of binding and ports </Services>
</definitions>

48
Types
<types>
• <types>
<schema define data types used in defining messages
targetNamespace=“http://example.com/stockquote.xsd”
xmlns=“http://www.w3.org/2000/10/XMLSchema”>
• <element
XML Schema, DTD, and etc.
name=“TradePriceRequest”>
• XML<complexType>
<all>Schema must be supported by any vendor of WSDL
conformant
<element products
name=“tickerSymbol” type=“string“
minOccur = “1” maxOccur=“10”/>
<element name = “payment”>
<complexType>
<choice>
<element name = “account” type=“string” />
<element name = “creditcard” type=“string” />
</choice>
</complexType>
</element>
</all>
</complexType>
</element>
</schema>
</types>
49
WSDL Messages
• A <message> element defines the data elements of an
operation
• Each message can be the input or output of an operation,
and may consist of one or more parts
• A part resembles a parameter of a function

<message name=“GetLastTradePriceInput”>
<part name=“body” element="TradePriceRequest"/>
</message>

<message name=“GetLastTradePriceOutput”>
<part name=“body” element=“TradePrice” />
</message>
50
WSDL PortTypes
• The <portType> element is the most important WSDL
element: it defines
– a web Services
<portType
– the name=“StockQuotePortType”>
operations that can be performed, and
<operation name=“GetLastTradePrice”>
– the messages that are involved
<input message=“tns:GetLastTradePriceInput” />
• The <port> defines the connection point to a web
<output message=“tns:GetLastTradePriceOutput” />
Services, an instance of <portType>
</operation>
– It can be compared to a function library (or a module,
</portType>
or a class) in a traditional programming language
– Each operation can be compared to a function in a
traditional programming language

51
Operation Types
• The request-response type is the most common operation
type, but WSDL defines four types:
– One-way: The operation can receive a message but will
not return a response
– Request-response: The operation can receive a request
and will return a response
– Solicit-response: The operation can send a request and
will wait for a response
– Notification: The operation can send a message but will
not wait for a response

• WSDL 1.2 adds: request – multiple response


52
Operation Types
One-way:
• <message name="newTermValues">
<part name="term" type="xs:string"/>
<part name="value" type="xs:string"/>
</message>
• <portType name="glossaryTerms">
<operation name="setTerm">
<input name="newTerm" message="newTermValues"/>
</operation>
</portType >

Request-response :
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>

<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>

53
Binding
• Binding defines how message are transmitted, and the
location of the Services
• <binding> element has two attributes:
– type: the port type
– name: name of the binding
• <soap:binding> has two attributes:
– style: either “document” or “rpc”
– transport: protocol to use, e.g., “http”

54
Binding
<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>
55
Services

<Services name=“StockQuoteServices”>
<documentation>
My first Services
</documentation>
<port name=“StockQuotePort”
binding=“tns:StockQuoteBinding”>
<soap:address
location=“http://example.com/stockquote” />
</port>
</Services>

56
Summary of WSDL
• Types
• Message
• Operation
• PortType
• Binding
• Port
• Service

57
Web Services Flow Description

58
Business Process Execution Language

• Define business processes as coordinated sets of Web


Services interactions
• Define both abstract and executable processes
• Enable the creation of compositions of Web Services
• Where it comes from:
– Strong roots in traditional flow models
– Concepts from structured programming languages
– On the top of WSDL and core XML specifications
– Merges WSFL and XLANG concepts
• The OASIS WS BPEL Technical Committee is advancing
the BPEL4WS Specification

59
BPEL Composition of Web Services

60
Structure of a BPEL Process
<process ...> • Web Services the process
interacts with
<partners> ...
</partners> • Data used by the process
<messageExchanges> ... • Used to support asynchronous
</ messageExchanges > interactions
<correlationSets> ... • Alternate execution path to
</correlationSets>
deal with faulty conditions
<faultHandlers> ...
</faultHandlers> • Code to execute when
<compensationHandlers> ... “undoing” an action
</compensationHandlers> • What the process actually does
(activities)*

</process>
61
Partner Definitions and Links
• A partner is accessed over a WS “channel”, defined by a
Services link type
<partner name=“...” ServicesLinkType=“...”
partnerRole=“...” myRole=“...”/>
• A SLT defines two roles and the portTypes that each role
needs to support
<ServicesLinkType name=“...”>
<role name=“...">
<portType name=“...” />*
</role>
<role name=“...”>
<portType name=“...”/>*
</role>
</ServicesLinkType>
62
Containers Definition
<containers>
<container name=“…"
messageType=“…"/>
<container name=“…"
messageType=“…"/>
</containers>

63
BPEL Basic Activities
• Invokes an operation on a partner
<invoke partner=“...” portType=“...” operation=“...”
inputContainer=“...” outputContainer=“...”/>
• Receives invocation from a partner
<receive partner=“...” portType=“...” operation=“...”
container=“...” [createInstance=“...”] />
• Sends a reply message in partner invocation
<reply partner=“...” portType=“...” operation=“...”
container=“...”/>
• Data assignment between containers
<assign>
<copy>
<from container=“...”/> <to container=“...”/>
</copy>+
</assign>
64
More Basic Activities

• Detects processing error and switches into fault processing mode

• Pull<throw
the plug faultName=“...”
on this instance faultContainer=“...”/>

• Execution stops for a specified amount of time


<terminate/>

• Do nothing; a convenience
<wait for=“...”? element />
until=“...”?

<empty/>

65
BPEL Structured Activities
• A <sequence> activity contains one or more activities that are performed sequentially.

• The <pick> activitystandard-attributes>activity+</sequence>


<sequence waits for the occurrence of exactly one event from a set of
events, thenexecutes the activity associated with that event.

• The <flow> activity provides concurrency and synchronization.


<pick createInstance="yes|no"? standard-attributes>…<pick>

• The<swith>activity provides optional activity.


<flow standard-attributes>activity+</flow>

<swith standard-attributes>
<case>…</case>

<otherwise>…</otherwise>
</swith>
66
More Structured Activities
• The <while> activity provides for repeated execution of a contained activity.

<while standard-attributes><condition>..</condition>activity</while>
• The <repeatUntil> activity provides for repeated execution of a contained
activity.

<repeatUntil standard-attributes>activity
<condition>…</condition></repeatUntil>
• The <if> activity provides conditional behavior.

<if standard-attributes>standard-elements
<condition>…</condition>activity
<elseif>*<condition>…</condition>activity</elseif>
<else>activity</else></if>

67
A Activities Use Case
<sequence>
<sequence>
<receive .../>
execute
<flow> activities sequentially Seq

<flow> <sequence>
<invoke ... /> Flow
execute activities in parallel Seq
<while ... > Seq

<while> <assign> ... </assign>


iterate execution
</while>of activities until condition is violated
<pick> </sequence> While
<sequence>
several event activities
<receive ... /> (receive message, timer event)
scheduled<invoke
for execution
... /> in parallel; first one is selected and
corresponding
</sequence>code executed
</flow>
<link ...>
<reply ... />
defines a control dependency between
</sequence>
a source activity and a target 68
Web Services Publication and
Discovery

69
UDDI
• UDDI servers act as a directory of available
services and service providers. SOAP can be used
to query UDDI to find the locations of WSDL
definitions of services, or the search can be
performed through a user interface at design or
development time.
• Data structure specification describes what kind of
data is stored in UDDI.
• The programmer’s API specification contains how
a UDDI registry can be accessed.
• The replication specification contains descriptions
of how registries replicate information among
themselves.
70
UDDI
• Three basic functions
– publish : how to register a web service
– Search: how to find a specific web service
– binding: How to connect to a web service

71
UDDI Registries
UDDI registries contains information about
businesses and the Services these businesses offer.

– Public registries
– Private registries

72
Public Registries

• IBM Public registry Registration:


https://uddi.ibm.com/ubr/registry.html
inquiryURL= https://uddi.ibm.com/ubr/inquiryapi
publishURL= https://uddi.ibm.com/ubr/publishapi

• Test registry Registration:


https://uddi.ibm.com/testregistry/registry.html
inquiryURL= https://uddi.ibm.com/testregistry/inquiryapi
publishURL= https://uddi.ibm.com/testregistry/publishapi

73
Public Registries
• HP
Registration: http://uddi.hp.com
inquiryURL = http://uddi.hp.com/ubr/inquire
publishURL = https://uddi.hp.com/ubr/publish

• Microsoft
Registration: http://uddi.rte.microsoft.com
inquiryURL=http://uddi.rte.microsoft.com/inquire
publishURL=https://uddi.rte.microsoft.com/publish

• SAP
Registration: http://udditest.sap.com
inquiryURL=http://uddi.sap.com/UDDI/api/inquiry/
publishURL=https://uddi.sap.com/UDDI/api/publish/ 74
Private UDDI Registries

• Operate your own registry for testing purposes

• Establish your own registry of Services for your own


organization

• Trust issue

75
Summary
• As a distributed computing architecture , Web Services are
the most important implementation for SOA;
• Web Services: Flexible machine-machine interaction;
• XML is a powerful language to describe data. It’s construct
rules is defined by XML Schema.
• SOAP is a light weight replacement for complicated distributed
object technology which we use to wrap Web Services
message;
• The function and interface of Web Services is open by WSDL
and the interaction between Web Services is presented by
BPEL;
• Universal Description, Discovery, and Integration (UDDI) is a
technical specification for describing, discovering, and
integrating web Services. 76
Reference
•SOA & Webservices.http://www-900.ibm.com/developerWorks/cn/
webservices
•WebServices. http://www.w3.org/2002/ws/
•Ueli Wahli ,Thomas Kjaer…“WebSphere Version 6 Web Services Handbook
Development&Deployment”,http://www.redbooks.ibm.com
/redbooks/pdfs/sg246461.pdf,2005
•Stan Kleijnen,Srikanth Raju.An Open Web Services Archiecture.NewYork:
ACM Press,2003
•XML.http://www.w3.org/TR/xml/
•XML Schema. http://www.w3.org/TR/xmlschema11-1/
•XML Schema. http://www.w3.org/TR/xmlschema11-2/
•WSDL. http://www.w3.org/TR/wsdl
•Tony Andrews, Francisco Curbera…Business Process Execution Language for
Web Services Version 1.1.http://download.boulder.ibm.com/
ibmdl/pub/software/dw/specs/ws-bpel/ws-bpel.pdf
•The Stencil Group.” The Evolution of UDDI ,UDDI.org White Paper”
http://www.uddi.org/pubs/the_evolution_of_uddi_20020719.pdf
•Java Web Services Application and development, Publication House of
77