Web Services: DR - Saranya K G Assistant Professor (S.GR) Dept - of CSE, PSG College of Technology, Coimbatore
Web Services: DR - Saranya K G Assistant Professor (S.GR) Dept - of CSE, PSG College of Technology, Coimbatore
Web Services: DR - Saranya K G Assistant Professor (S.GR) Dept - of CSE, PSG College of Technology, Coimbatore
Dr.Saranya K G
Assistant Professor(S.Gr)
Dept.of CSE,
PSG College of Technology,
Coimbatore
What is a Web Service
• A web service is a network accessible interface to
application functionality, built using standard
Internet technologies.
• Clients of web services do NOT need to know how
it is implemented.
Application Application
Network Web
client Service code
Web Service Technology Stack
shopping web service?
Discovery Web Service UDDI
WSDL URIs
Client
Transport
Network
Step1. Write Web Service Method
shopping web service?
Discovery Web Service UDDI
WSDL URIs
Client
Transport
Network
Step2. Describe Web Service using WSDL
shopping web service?
Discovery Web Service UDDI
WSDL URIs
Client
Transport
Network
Step3. Write Proxy to Access Web Service
shopping web service?
Discovery Web Service UDDI
WSDL URIs
Client
Transport
Network
Step4. Write Client to Invoke Proxy
shopping web service?
Discovery Web Service UDDI
WSDL URIs
Client
Transport
Network
Step1. Create a Web Service
• Functionality is implemented in .asmx.vb or .asmx.cs
files.
• <%@WebService Language=“C#” Class=“helloWorld” %>
• Use System.Web.Services Namespace
• Using System.Web.Services
• Inherit your own class from WebService Base Class
• public class helloWorld : System.Web.Services.WebService
• Declare the WebMethod Attribute
• [WebMethod]
public string HelloWorld(string name)
{…}
Web Services - Definition from W3C
“ A Web service is a software system identified by a URI, whose public
interfaces and bindings are defined and described using XML. Its
definition can be discovered by other software systems. These
systems may then interact with the Web service in a manner
prescribed by its definition, using XML based messages conveyed by
internet protocols.”
Service Oriented Architectures
One-way, Component
conversational, many-
to-many
Web Services –
Architectural Extensions
• Incorporates additional features and functionality by extending
technologies and components defined within the basic architecture, such
as:
• Asynchronous messaging
• Attachment – typical usage : associating binary data with SOAP messages.
• Caching
• Message exchange pattern (MEP) - Describes a generalized pattern of message
exchange between two services. e.g. : one-way, request/response,
publish/subscribe, and broadcast.
• Reliable message - implementation of Reliable Messaging one MEP is a series
of requests between two nodes with an acknowledgement SOAP Module.
• Message confidentiality – Can transmit the message via SSL or TLS, or have a
SOAP Module provides for encryption and decryption.
• Message integrity – Can have a SOAP Module use digital signature.
• Session
The Complete Web Services "Stack"
More
mature
technologie
s
The Wire Stack
•Transport: HTTP is
the de facto, other
may be supported.
•Packaging: SOAP is
the de facto standard
for XML messaging.
•Extensions :
Additional information
attached to web
services messages.
The Description Stack
It is actually a stack of description
documents defined using XML
Schema.
Not fully
specified
facts, or assertions, and
rules that apply to a
particular Web service
Input/
Output
rendering
minimum service description
necessary to support Satisfied
interoperable Web services. by WSDL
The Discovery Stack
WSIL : de-centralized
service discovery method
<xhtml:table><xhtml:tr>
<xhtml:td width="40%">LastName</xhtml:td>
<xhtml:td width="60%">Allen</xhtml:td>
</xhtml:tr></xhtml:table>
How to work on XML
The tree-like structure of XML makes developers
life hard.
In practice there is not a standard way for
editing and analyzing, but the best method
depends on your need. Just choose among:
SAX -> callback-based parser
DOM -> tree representation
XSLT -> “XML to XML” conversion
XPATH -> queries
XML Binding -> transparent conversion to
objects
Simple Object Access Protocol
SOAP is a technology to support the exchange of
XML-coded messages over a transport protocol,
such as HTTP and SMTP. (wire stack)
SOAP SOAP
POST…
HTTP client HTTP server
Protocols Folding HTTP 1.1 200 OK
ClockService.getTime(location="USA");
Service Request
<soap:Body>
<getTime>
<location xsi:type="xsd:string">USA</path>
</getTime>
</soap:Body>
Web Service Description Language
WSDL is a standard format to describe a Web
Service (description stack)
<inspection>
<abstract>Acme Industries Public Web Services</abstract>
<service>
<name>Store Finder Service</name>
<abstract>
A service to perform a geographical search of Acme stores.
</abstract>
<description
location="http://example.org/services/storefinder.wsdl"/>
</service>
<link location="http://example.org/services/ecommerce.wsil"/>
</inspection>
Service name
Link to an other WSIL page
Service location and description
UDDI
UDDI is a complimentary approach for searching
based on a centralized repository.
- Message transportation
Service Transport
- HTTP, SMTP, FTP, BEEP
• Message structure
• Processing model
• Protocol bindings
SOAP
Messages
• XML Envelope
• Body
• Application payload
• Faults
• Headers
• Metadata, processing instructions
• May be marked as mandatory
• Possibly targeted at intermediaries
SOAP
Message Example
<soap:Envelope namespaces…>
<soap:Header>
<wsa:MessageID> unique ID </wsa:MessageID>
<wsa:ReplyTo> endpoint </wsa:ReplyTo>
</soap:Header>
<soap:Body>
<bank:BalanceRequest>
data
</bank:BalanceRequest>
</soap:Body>
</soap:Envelope>
SOAP
Message Envelope
Body
Header
SOAP
Processing Model
• Processing a message
• mustUnderstand="true"
• The recipient must understand them
• Implies agreement to act in accordance to the spec
• Non-mandatory headers can be ignored
• Addressing: URIs
• Serialization: HTTP message body
• Media type application/soap+xml
• Connection: TCP
• Possibly Web-friendly
• SOAP 1.1 only used HTTP POST
SOAP
MEPs
• Request-Response
• Input message followed by output or fault
• SOAP-Response
• Request without SOAP (e.g. HTTP GET)
• SOAP output or fault
SOAP
Summary
• Still pretty simple even if the name doesn’t say so any more
• Extremely extensible
• HTTP binding for easy communication
<S:Header>
<wsa:MessageID> unique ID </wsa:MessageID>
<wsa:ReplyTo> endpoint </wsa:ReplyTo>
<wsa:To> address </wsa:To>
<wsa:Action> URI </wsa:Action>
</S:Header>
WSDL
Overview
service
service
service
WSDL
Component Structure
service
service
service
endpoint
endpoint
WSDL
Component Structure
interface
interface
interface
service
service
service
endpoint
endpoint
WSDL
Component Structure
interface
interface
interface
operation
operation
operation
fault
fault
fault
service
service
service
endpoint
endpoint
WSDL
Component Structure
interface
interface
interface
operation
operation
operation
fault
fault
fault binding
interface
interface
service
service
service
endpoint
endpoint
WSDL
Component Structure
interface
interface
interface
operation
operation
operation
fault
fault
fault binding
interface
interface
operation
operation
operation
service
service
service fault
fault
fault
endpoint
endpoint
WSDL
Component Structure
interface
operation
operation
operation
fault fault
fault
WSDL
Component Structure
interface
operation
operation
operation
message
msg ref
ref
msg ref
fault
msg ref
msgref
ref
fault fault
fault
WSDL
Component Structure
interface
operation
operation
operation
types
message
msg ref
ref
msg ref
fault
msg ref
msgref
ref
fault fault
fault
WSDL
Component Structure
interface
operation
operation
operation
types
message
msg ref
ref
msg ref
element declaration
operation
operation
fault
msg ref
msgref
ref
type definition
fault
fault
fault fault
fault
WSDL
Component Structure
interface
operation
operation
operation
types
message
msg ref
ref
msg ref
element declaration
operation
operation
fault
msg ref
msgref
ref
type definition
fault
fault
fault fault
fault
WSDL
Interface
Invocation: Messaging:
• SOAP binding:
• XML message in SOAP envelope
• Transport using a SOAP protocol binding (HTTP)
• HTTP binding:
• Web-friendly
• XML message in payload, or as parameters in the URI
WSDL
Service
<service name=“HypoTirol”
interface=“Banking”>
<endpoint name=“visible”
binding=“HTTP”
address=“http://ht.at/bankingSvc” />
<endpoint name=“tls”
binding=“SecureHTTP”
address=“https://ht.at/bankingSvc” />
</service>
WSDL
Summary
• Concrete service
• Abstract and reusable Interface
• Network binding
• Business entity
• Organization information, contact
• Business Service
• A group of related services
• Binding Template
• Information on how to access the service
• tModel (technical model)
• Any kind of specification, e.g. WSDL
• Also for classification, categorization
WS-Policy
Overview • Non of the previous solutions is addressing the non-functional aspects in the
context of Web Services
• e.g., a Web Service can be accessed only if a particular security constrains (like
secure channel communication) hold.
• WS-Policy is an XML-based set of specifications to advertise and specify service-
related non-functional metadata
• Security, Quality of service, Privacy, Transactional policies
• WS-Policy main specifications
• WS-Policy Framework
• Provides model and syntax to describe and communicate policies
• WS-Policy Assertions
• Defines a common set of policy assertions for Web services
• WS-Policy Attachments
• General-purpose mechanisms for associating such policies with the subjects to which
they apply
• Capability vs. requirement policy
WS-Policy
A Policy
• Policy is a collection of policy alternatives (OR)
• Auth tokens: Kerberos OR X509
• Policy alternative is a collection of policy assertions (AND)
• Auth token AND secure channel
• Policy assertions specify
• traditional policies that will ultimately manifest on the wire (authentication
scheme, transport protocol selection), and
• critical to proper service selection and usage (privacy policy, QoS
characteristics).
• Two "operators" (XML tags) are used to make statements about policy
combinations:
• wsp:ExactlyOne - asserts that only one child node must be satisfied.
• wsp:All - asserts that all child nodes must be satisfied.
• The intersection is a new policy that complies with both their
requirements/capabilities
WS-Policy
An Example of the Security Policy
<wsp:Policy>
<wsp:ExactlyOne>
<wsse:SecurityToken>
<wsse:TokenType>wsse:Kerberosv5TGT
</wsse:TokenType>
</wsse:SecurityToken>
<wsse:SecurityToken>
<wsse:TokenType>wsse:X509v3
</wsse:TokenType>
</wsse:SecurityToken>
</wsp:ExactlyOne>
</wsp:Policy>
WS-BPEL
Overview
• WS-BPEL is an orchestration executable language for
specifying interactions with Web Service
• Defines an interoperable integration model for Web Service-based processes.
• Describes high-level state transition interactions of a process.
• The language supports following basic facilities:
• Message exchanges,
• Property-based message correlation mechanism,
• XML and WSDL typed variables,
• Structured programming-language concepts such as if-then-else,
while, sequence, and flow,
• Scoping system to allow encapsulation of logic with local-
variables, fault-, compensation- and event- handlers,
• Serialized scopes to control concurrent access to variables,
• Language plug-in model which allows expression writing in the
language such as XPath
WS-BPEL
WS-BPEL v2.0 MetaModel
• Activity
• Perform the process logic.
• Basic vs. structured activities.
• PartnerLink
• Models peer-to-peer conversational partner relationships.
• Catch
• Scope-based custom fault-handling activities.
• Correlation
• Used to differentiate instances of the business processes.
• The declaration of correlation relies on declarative properties of messages.
• onEvent
• Scope-based concurrent answering to events
• onEvent vs, onAlarm
WS-BPEL
An Example
Example figures and WSBPEL specification taken from OASIS standard Web Services Business Process
Execution Language Version 2.0, 11 April 2007
WS-BPEL
An Example
<process name="purchaseOrderProcess" targetNamespace=http://example.com/ws-bp/purchase
xmlns=http://docs.oasis-open.org/wsbpel/2.0/process/executable
xmlns:lns="http://manufacturing.org/wsdl/purchase">
<partnerLinks>
</partnerLinks>
<variables>
</variables>
<faultHandlers>
</catch>
</faultHandlers>
…
WS-BPEL …
An Example
<sequence>
variable="PO" createInstance="yes”>
</receive>
<flow>
<links>
</links>
<sequence>
<assign>
<copy>
<from>$PO.customerInfo</from>
<to>$shippingRequest.customerInfo</to>
</copy>
</assign>
inputVariable="shippingRequest" outputVariable="shippingInfo">
<sources>
</invoke>
variable="shippingSchedule”>
<sources>
</sources>
</receive>
</sequence>
…
WS-BPEL
An Example …
<sequence>
operation="initiatePriceCalculation” inputVariable="PO”>
</invoke>
inputVariable="shippingInfo”>
</invoke>
variable="Invoice" />
</sequence>
<sequence>
operation="requestProductionScheduling” inputVariable="PO">
</invoke>
inputVariable="shippingSchedule”>
</invoke>
</sequence>
</flow>
variable="Invoice”>
</reply>
</sequence>
</process>
The Rest of the Specs
• Security: authentication, encryption
• Reliable messaging
• “Get the message there or tell me”
• Transactions: ACID, Compensating
• WS-BPEL: Scripting Web Services
• Interoperability: WS-I Basic Profile
• … and still more
ILLUSTRATION BY A
LARGER EXAMPLE
Virtual Travel Agency
Blue Hotel WSDL (1)
<?xml version="1.0" encoding="utf-8" ?>
<description
xmlns="http://www.w3.org/ns/wsdl"
targetNamespace=
"http://www.bluehotel.com/wsdl/BlueHotelService"
xmlns:tns=
"http://www.bluehotel.com/wsdl/BlueHotelService"
xmlns:bhns=
"http://www.bluehotel.com/schemas/BlueHotelService"
xmlns:wsoap= "http://www.w3.org/ns/wsdl/soap"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsdlx= "http://www.w3.org/ns/wsdl-extensions">
<documentation>
This document describes the Blue Hotel Web service.
</documentation>
Blue Hotel WSDL (2)
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.bluehotel.com/schemas/BlueHotelService"
xmlns="http://www.bluehotel.com/schemas/BlueHotelService">
<xs:element name="checkAvailability" type="tCheckAvailability"/>
<xs:complexType name="tCheckAvailability">
<xs:sequence>
<xs:element name="checkInDate" type="xs:date"/>
<xs:element name="checkOutDate" type="xs:date"/>
<xs:element name="roomType" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="checkAvailabilityResponse"
type="tCheckAvailabilityResponse"/>
<xs:complexType name="tCheckAvailabilityResponse">
<xs:sequence>
<xs:element name="roomType" type="xs:string"/>
<xs:element name="rateType" type="xs:string"/>
<xs:element name="rate" type="xs:double"/>
</xs:sequence>
</xs:complexType>
<xs:element name="invalidDataError" type="xs:string"/>
</xs:schema>
</types>
Blue Hotel WSDL (3)
<interface name = "BlueServiceInterface" >
<operation name="opCheckAvailability"
pattern="http://www.w3.org/ns/wsdl/in-out"
style="http://www.w3.org/ns/wsdl/style/iri"
wsdlx:safe = "true">
<input messageLabel="In"
element="bhns:checkAvailability" />
<output messageLabel="Out"
element="bhns:checkAvailabilityResponse" />
<outfault ref="tns:invalidDataFault" messageLabel="Out"/>
</operation>
</interface>
Blue Hotel WSDL (4)
<binding name="BlueServiceSOAPBinding"
interface="tns:BlueServiceInterface"
wsoap:protocol=
"http://www.w3.org/2003/05/soap/bindings/HTTP/"
type="http://www.w3.org/ns/wsdl/soap">
<fault ref="tns:invalidDataFault"
wsoap:code="soap:Sender"/>
<operation ref="tns:opCheckAvailability"
wsoap:mep=
"http://www.w3.org/2003/05/soap/mep/soap-response"/>
</binding>
<service name="BlueService"
interface="tns:BlueServiceInterface">
<endpoint name="reservationEndpoint"
binding="tns:BlueServiceSOAPBinding"
address="http://www.bluehotel.com/BlueService"/>
</service>
</description>
Blue Hotel UDDI Binding
Template
<bindingTemplate
bindingKey=
"uuid:36F1B765-BDB3-4837-828D-8284301E5A2A"
serviceKey=
"uuid:40E6D5A8-3E16-4f01-99DA-035229685A40">
<description xml:lang="en">
SOAP binding for Blue Hotel service
</description>
<accessPoint URLType="http">
http://www.bluehotel.com/hotel:80/soap
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey=
"uuid:AE1B645F-CF2F-491f-811A-4868705F5904"/>
</tModelInstanceDetails>
</bindingTemplate>
Blue Hotel UDDI tModel
<tModel tModelKey=
"uddi:WE1B6Q5F-CF2F-491f-811A-4868705F5904"
operator="http://www.bluehotel.com/hotel"
authorizedName="George Blue">
<name>BlueHotelInterface Port Type</name>
<description>
An interface for the Blue Hotel service
</description>
<overviewDoc><overviewURL>
http://www.bluehotel.com/services/
BlueHotelService.wsdl
</overviewURL></overviewDoc>
</tModel>
Blue Hotel SOAP Request
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope soap:encodingStyle=
"http://www.w3.org/2001/12/soap-encoding"
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body xmlns:bhns=
"http://www.bluehotel.com/wsdl/BlueHotelService">
<bhns:checkAvailability>
<bhns:checkInDate>2009-03-24</bhns:checkInDate>
<bhns:checkOutDate>2009-03-30</bhns:checkOutDate>
<bhns:roomType>Single</bhns:roomType>
</bhns:checkAvailability>
</soap:Body>
</soap:Envelope>
Blue Hotel SOAP Response
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope soap:encodingStyle=
"http://www.w3.org/2001/12/soap-encoding"
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body xmlns:bhns=
"http://www.bluehotel.com/wsdl/BlueHotelService">
<bhns:checkAvailabilityResponse>
<bhns:roomType>Single</bhns:roomType>
<bhns:rateType>Discount</bhns:rateType>
<bhns:rate>150.50</bhns:rate>
</bhns:checkAvailabilityResponse>
</soap:Body>
</soap:Envelope>
SUMMARY
Web Services Summary
• Technology for service-oriented systems
• Core: protocol + IDL (SOAP + WSDL)
• Many extension specifications
• Messaging paradigm
• Sometimes RPC
• Biggest benefit: XML
• Vendor-neutral, platform-independent
• Interoperable
• Easy to begin and play with
• But hidden in the frameworks
• Unless you're a developer of the framework
Possible Extensions
• Semantic Web Services
• Automating the use of Web services
• Using semantic technologies
• RESTful services
• Real Web services
• Integrated with the Web
References
• Mandatory reading:
• G. Alonso, F. Casati, H. Kuno, V. Machiraju. Web Services, Concepts
Architectures and Applications. Springer Verlag ISBN 3-540-44008-9
• WSDL http://w3.org/TR/wsdl20
• SOAP http://w3.org/TR/soap12
• UDDI http://uddi.xml.org/
References
• Further reading:
• XOP http://w3.org/TR/xop10
• MTOM http://w3.org/TR/soap12-mtom
• WS-Addressing http://w3.org/TR/ws-addr-core
• WS-Policy http://w3.org/TR/ws-policy
• WS-BPEL http://docs.oasis-open.org/wsbpel/2.0/OS/wsbpel-v2.0-OS.html
• OASIS http://oasis-open.org/
• W3C http://w3.org/