faculty of information technology 31284 web service development week 10 – web services intro
TRANSCRIPT
Faculty of Information Technology
31284 Web Service Development
Week 10 – Web services Intro
2
Faculty of Information Technology
Web Applications
• Presentation-oriented: – PAGE based– App generates Markup pages (HTML, XHTML etc)– “Human oriented”:
• user interacts with page: Request/Response – B2C & B2C
• Service-oriented: “web services”– Service based– Application provides “Remote Procedure Calls/Remote
Methods” – “Machine oriented”:– Application interacts with Application:
• Request/Response (RPC) • Message oriented
3
Faculty of Information Technology
Web Services – problems solved
• Before Web: – Traditional approach:
“Remote Procedure Calls” or “Remote Method Invocation”
– Tied to the underlying architecture– Binary message formats– Compatibility issues– Proprietary technologies and implementations– Expensive, Inflexible, Complex– Not firewall friendly
4
Faculty of Information Technology
Web services – problems solved
• After Web:– Different vendors attempted HTTP based solutions– Web based RPC:
• Just send and receive plain text via a URL
– XML based RPC:• Send/receive requests as XML
XML-RPC “standard” (http://en.wikipedia.org/wiki/Xml-
rpc)– Language & technology neutral, but not a
standard Influenced standards formalised as SOAP.
5
Faculty of Information Technology
Web services - definition
• “Web services are self-contained, self-describing, modular applications that can be published, located, and invoked across the web.”
• “Web service applications are encapsulated, loosely coupled web ‘components’ that can bind dynamically to each other.”
• Web Services a distributed computing platform
6
Faculty of Information Technology
W3C web services standard
W3C standard for web services:
• An application (Consumer) connects to another application (Provider) via SOAP
• The Consumer knows how to connect to the Provider because the interface is described with WSDL.
• The Consumer can find the Provider because the provider’s details are published in a UDDI registry.
• Both communicate using the web protocol, HTTP.
• The data exchange is via XML and XML Schema
7
Faculty of Information Technology
Web Services Introduction
8
Faculty of Information Technology
SOAP
• “Simple Object Access Protocol”
• SOAP message contains:– Envelope:
describes the message and how to process it
– Header: contains the features of the SOAP message
– Body: contains the primary information for the message receiver
9
Faculty of Information Technology
SOAP
• SOAP works by transmitting XML between the Consumer and Provider.
• Akin to “Snail Mail” – Envelope is like the mail address, Body is like the content of the letter
10
Faculty of Information Technology
SOAP
SOAP is a XML Message format
Calls and responses are sent as SOAP Envelopes.
The message in a SOAP Envelope has a header (optional) and a body.
The Body is for application level data.Parameters, method calls etc.
The Header is for infrastructure level data.Authentication, coordination etc.Header attributes:
actor (none, next, ultimateReceiver)mustUnderstand (1 or 0)
11
Faculty of Information Technology
SOAP Request 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 xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
getStockPrice(“IBM”)
12
Faculty of Information Technology
SOAP Request 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 xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body></soap:Envelope>
getStockPrice(“IBM”) 34.5
13
Faculty of Information Technology
SOAP Summary
• SOAP is a simple protocol intended for transferring data from one application to another.
• SOAP provides a mechanism for encapsulating RPC calls into SOAP messages (in envelopes).
• SOAP uses existing, recognised standards to solve problems ofdata representation and transport.
Some SOAP downfalls:• No mechanisms for reliability, transactions, security…
• SOAP is, in itself, not adequate for all needs in industrial applications
• Extra standards to add missing functionality include – WS-reliable messaging,– WS-Security– WS-Coordination, WS-Transactions
14
Faculty of Information Technology
WSDL
• How do you know how to invoke a web service?– SOAP only specifies the format for message exchange, it
doesn’t say what the message itself should contain!
– What is the address of the web service?– What are the required parameters?– What protocols are used?
• Web Services Description Language (WSDL) specifies the answers to these questions
15
Faculty of Information Technology
WSDL Structure
Service:– collection of endpoints– endpoint = port + binding
Binding: – maps operations to protocols
(e.g. SOAP via HTTP)
Port type: – a set of operations supported
by endpoints (like a function library)
Operation: – abstract description of an
action supported by a service
Message: – typed definition of data
communication (input and output)
16
Faculty of Information Technology
WSDL Elements
• <service>– Groups related ports together– eg. If a portType is bound to two protocols, they
are grouped together
• <port>– Specifies the location of the web service
17
Faculty of Information Technology
WSDL Elements
<service name="CalculatorService"><port name="CalculatorPort" binding="tns:CalculatorPortBinding"><soap:address location="http://localhost:8888/calculator"/></port>
</service>
18
Faculty of Information Technology
WSDL Elements
• <binding>– Specifies protocols used to invoke web service
• Eg. Is this a SOAP web service? Over HTTP?
– The abstract interface defined in <portType> can be bound to different messaging and transport protocols
• Eg. SOAP over HTTP, SOAP over SMTP, …
19
Faculty of Information Technology
WSDL Elements
<binding name="CalculatorPortBinding" type="tns:Calculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="add"><soap:operation soapAction=""/><input>
<soap:body use="literal"/></input><output>
<soap:body use="literal"/></output>
</operation></binding>
20
Faculty of Information Technology
WSDL
• <portType>– Defines the interface (similar to Java interface
definition)
• <operations>– Defines the actions (similar to Java methods)
<portType name="Calculator"><operation name="add">
<input message="tns:add"/><output message="tns:addResponse"/>
</operation></portType>
21
Faculty of Information Technology
WSDL Elements
• <message>– Defines a set of parameters– Defined messages are referred to in the
<portType> element
<message name="add"><part name="parameters" element="tns:add"/>
</message><message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
</message>
22
Faculty of Information Technology
WSDL Elements
• <types>– Defines the data types used– Referred to by <message> elements – Usually uses XML schema to define types
23
Faculty of Information Technology
WSDL Elements
<types><xs:schema targetNamespace="http://server/">
<xs:element name="add" type="tns:add"/><xs:complexType name="add"> <xs:sequence>
<xs:element name="arg0" type="xs:int"/><xs:element name="arg1" type="xs:int"/>
</xs:sequence></xs:complexType><xs:element name="addResponse“
type="tns:addResponse"/>…. & so on….
24
Faculty of Information Technology
Agenda
• Introduction to Web Services
• Enabling technologies: SOAP and WSDL, UDDI
• JAX-WS
25
Faculty of Information Technology
JAX-RPC
• JAX-RPC was the older standard for interfacing web services with Java
• This had several flaws – not so easy to use, mainly dealt with RPC style transactions, not built into Java
• JAX-RPC 2.0 was a refresh & got renamed to JAX-WS
26
Faculty of Information Technology
JAX-WS
• Now built into Java 6
• Concept: you write POJO (Plain Old Java Objects) and annotate your code with @WebService and @WebMethod
• (next slides are from Sun Java user group, tech days 2008 (Carol McDonald))
27
Faculty of Information Technology
Developing with JAX-WS
28
Faculty of Information Technology
Writing service
29
Faculty of Information Technology
JAX-WS mapping
30
Faculty of Information Technology
Customising
31
Faculty of Information Technology
Client side
32
Faculty of Information Technology
Client
33
Faculty of Information Technology
34
Faculty of Information Technology
Labs
• We will develop both a server and client using JAX-WS in the labs
35
Faculty of Information Technology
Questions?