Professional Documents
Culture Documents
Objective
– What Is a Web Service?
– Identifying Web Service Standards
– JEE Web Service APIs
– Using Java API for XML based-WS API (JAX-WS)
– Developing a Web Service by Using the Bottom-
Up Approach
– Invoking the Web Service with a Java Client
Application
– Developing a Web Service by Using the Top-
Down Approach
What is Service ?
• A service is a behavior that is provided by a
component for use by any other component
based only on the interface contract.
• A service has a network-addressable interface.
• A service may be dynamically discovered and
used.
Service-oriented Architecture
• SOA is a design and a way of thinking about building s/w components.
Benefits of SOA
• Better reuse
– Build new client functionality on top of existing
Business Services
• Well defined interfaces
– Make changes without affecting clients
• Easier to maintain
– Changes/Versions are not all-or-nothing
• Better flexibility
What is a Web Service?
• In simpler terms…
– Software that performs a task.
• Sits on a network so other systems can talk to
it (most often SOAP over HTTP).
• Has a defined, published interface (via WSDL).
• Is platform and language independent.
• Typically uses XML.
Web service standards
Web services programming stack.
<SOAP-ENV:Header>
<t:Transaction
xmlns:t="some-URI" SOAP-ENV:mustUnderstand="1">
5
</t:Transaction>
</SOAP-ENV:Header>
• SOAP Body
– SOAP envelope’s child element
– one or more optional SOAP body block entries
– mandatory processing information or the payload intended for the
receiver
– Body block can contain…
• RPC method and its parameters
• Target application (receiver) specific data
• SOAP fault for reporting errors and status information
• SOAP Fault
– error and/or status information
– elements to define the error and status
• Faultcode (VersionMismatch, MustUnderstand, Client, Server)
Faultstring, Faultactor, Detail
• SOAP mustUnderstand
– the processing of a SOAP header block is mandatory
or optional at the target SOAP node
• SOAP Attachments
– An XML format and any data format (can be ASCII or
binary)
Examples of SOAP Messages
• SOAP Message Embedded in HTTP Request
<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">
<symbol>L&T</symbol>
</m:GetLastTradePrice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
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>
SOAP Communication
• SOAP RPC
– remote procedural call-based synchronous
communication
– tightly coupled communication model based on
requests and responses.
• SOAP Messaging
– document-driven communication
– Using synchronous and asynchronous messaging
– loosely coupled communication model based on
message notification and the exchange of XML
documents
Web service Description Language -WSDL
• “Interface Definition Language (IDL) service based on XML that
defines the service interface and its implementation characteristics.”
WSDL document contains following (W3C spec):
Types– a container for data type definitions using some type system
(such as XSD).
Message– an abstract, typed definition of the data being communicated.
Operation– an abstract description of an action supported by the
service.
Port Type–an abstract set of operations supported by one or more
endpoints.
Binding– a concrete protocol and data format specification for a
particular port type.
Port– a single endpoint defined as a combination of a binding and a
network address.
Service– a collection of related endpoints.
The main structure of a WSDL document :
• <definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
definition of a port.......
</portType>
<binding>
definition of a binding....
</binding>
</definitions>
WSDL Ports
The <portType> element is the most important WSDL element.
It describes a web service, the operations that can be performed, and the
messages that are involved.
WSDL Messages
The <message> element defines the data elements of an operation.
Each message can consist of one or more parts. The parts can be compared
to the parameters of a function call in a traditional programming language.
WSDL Types
The <types> element defines the data types that are used by the web
service.
For maximum platform neutrality, WSDL uses XML Schema syntax to define
data types.
WSDL Bindings
The <binding> element defines the message format and protocol details for
each port.
UDDI
• The Universal Description, Discovery, and Integration (UDDI) specifications
define how to publish and discover information about services in a UDDI-
conforming registry.
• The UDDI schema identifies the types of XML data structures that comprise an
entry in the registry for a service.
Points to
UDDI description
Registry
WSDL
Points to
service
Finds Describes
Service Service
Web
WebService
Service SOAP Web
WebService
Service
Client
Client (J2EE,
(J2EE,PL/SQL,
PL/SQL,
(J2EE, .NET,C/C++,
(J2EE,.NET,
.NET, .NET,C/C++,
PL/SQL Legacy
Legacy…)
PL/SQL…)…) Invokes with …)
XML Messages
Building Web Services with JAX-WS
What is JAX-WS
JAX-WS is a technology for building web services and
clients that communicate using XML.
JAX-WS allows developers to write message-
oriented as well as RPC-oriented web services.
In JAX-WS, a remote procedure call is represented by
an XML-based protocol such as SOAP.
Why JAX-WS ?
Platform independence of the Java programming
language.
JAX-WS client can access a web service that is not
running on the Java platform, and vice versa.
It provides a complete Web services stack that eases
the task of developing and deploying Web services.
JAX-WS also includes the Java Architecture for XML
Binding (JAXB) and SOAP with Attachments API for Java
(SAAJ).
JAX-WS speeds up Web services development by
providing a library of annotations to turn plain old
Java object (POJO) classes into Web services.