Web Services
Web Services
JEFFREY C. JACKSON
Chapter 9
Web Services:
JAX-RPC, WSDL, XML Schema,
and SOAP
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
Web Services Concepts
• A web application uses Web technologies
to provide functionality to an end user
• A web service uses Web technologies to
provide functionality to another software
application
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
Web Services Components
• XML – eXtensible Markup Language – A uniform
data representation and exchange mechanism.
• SOAP – Simple Object Access Protocol – A
standard way for communication.
• UDDI – Universal Description, Discovery and
Integration specification – A mechanism to
register and locate WS based application.
• WSDL – Web Services Description Language –
A standard meta language to described the
services offered.
Web Services Concepts
• Standard web services technologies:
– Communication via SOAP XML vocabulary
documents over HTTP
– Operations of web service defined by Web
Services Definition Language (WSDL) XML
vocabulary
– Data within WSDL defined using XML
Schema
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
Web Services Concepts
• Higher-level API’s are often used to
automatically generate web services client
and server communication software
– We will use the Java API for XML-based
Remote Procedure Call (JAX-RPC)
– Microsoft .NET framework is one popular
alternative to JAX-RPC
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
Web Services Concepts
• Web services conceptually are just
specialized web applications:
Server
Client (Java servlet)
HTTP response (SOAP body)
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
Web Services Concepts
• WSDL defines web service
– Operations
– Parameters
– Return values
– Communication protocols
• Basically an API for the web service
– Facilitates automated client/server software
generation
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• How do we send a Java double value to a
web service using XML?
– Is scientific notation allowed?
– How large can the value be?
– Etc.
• What if we want to send an object?
– And what if the object contains references to
other objects?
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• XML Schema addresses such questions
– Defines a number of simple data types,
including
• Range of allowed values
• How values are represented as strings
– Provides facilities for defining data structures
in terms of simple types or other data
structures
• Can also be used in place of XML DTD
(Document Type Definition)
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• Built-in data types Built-in type
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• Built-in data types
– integer and decimal (arbitrary precision)
– dates, times, and related subtypes
– URLs
– XML namespace qualified names
– binary data
– some restricted forms of the above, e.g.,
nonNegativeInteger
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• XML Schema namespace defining built-in
types is called the document namespace
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• Mapping from XML Schema data types to
Java:
– Primitives: one-for-one mapping
– date, time, dateTime: map to Calendar
– most others: map to String
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• Elements in the document namespace can
declare user-defined data types
• Two XML Schema data types:
– Complex: requires markup to represent within
an XML document
– Simple: can be represented as character data
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• User-defined data types are declared in
the types element of a WSDL
– Example: ExchangeValue
• In WSDL, user-defined types can be used
– To define other data types within types
element
– To specify data types of parameters and
return values in message elements
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML Schema
• An XML schema is markup that
– Is written according to the XML Schema
vocabulary
– Defines an XML vocabulary
• A schema document is an XML document
consisting entirely of an XML schema
• A document conforming with an XML
schema vocabulary is call an instance of
the schema
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0
XML
• XML stands for EXtensible Markup
Language.
• XML is a markup language much like
HTML.
• XML was designed to describe data.
• XML tags are not predefined. You must
define your own tags.
• The prefect choice for enabling
cross-platform data communication in Web
Services.
XML vs HTML
An HTML example:
<html>
<body>
<h2>John Doe</h2>
<p>2 Backroads Lane<br>
New York<br>
045935435<br>
[email protected]<br>
</p>
</body>
</html>
XML vs HTML
• This will be displayed as:
John Doe
2 Backroads Lane
New York
045935435
[email protected]
• HTML specifies how the document is to be
displayed, and not what information is contained in
the document.
• Hard for machine to extract the embedded
information. Relatively easy for human.
XML vs HTML
• Now look at the following:
<?xml version=1.0?>
<contact>
<name>John Doe</name>
<address>2 Backroads Lane</address>
<country>New York</country>
<phone>045935435</phone>
<email>[email protected]</email>
</contact>
• In this case:
– The information contained is being marked, but not for
displaying.
– Readable by both human and machines.
SOAP
• SOAP originally stood for "Simple Object Access
Protocol" .
• Web Services expose useful functionality to Web
users through a standard Web protocol called
SOAP.
• Soap is an XML vocabulary standard to enable
programs on separate computers to interact
across any network. SOAP is a simple markup
language for describing messages between
applications.
• Soap uses mainly HTTP as a transport protocol.
That is, HTTP message contains a SOAP
message as its payload section.
SOAP Characteristics
• SOAP has three major characteristics:
– Extensibility – security and WS-routing are
among the extensions under development.
– Neutrality - SOAP can be used over any
transport protocol such as HTTP, SMTP or
even TCP.
– Independent - SOAP allows for any
programming model .
SOAP Building Blocks
A SOAP message is an ordinary XML document
containing the following elements:
– A required Envelope element that identifies the XML
document as a SOAP message.
– An optional Header element that contains header
information.
– A required Body element that contains call and
response information.
– An optional Fault element that provides information
about errors that occurred while processing the
message.
SOAP Request
POST /InStock HTTP/1.1
Host: www.stock.org
Content-Type: application/soap+xml; charset=utf-8 Content-Length: 150
<?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.stock.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
SOAP Response
HTTP/1.1 200 OK
Content-Type: application/soap; charset=utf-8
Content-Length: 126
<?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.stock.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
WSDL
• WSDL stands for Web Services Description Language.
• WSDL is an XML vocabulary for describing Web
services. It allows developers to describe Web Services
and their capabilities, in a standard manner.
• WSDL specifies what a request message must contain
and what the response message will look like in
unambiguous notation. In other words, it is a contract
between the XML Web service and the client who wishes
to use this service.
• In addition to describing message contents, WSDL
defines where the service is available and what
communications protocol is used to talk to the service.
The WSDL Document Structure
• A WSDL document is just a simple XML
document.
• It defines a web service using these major
elements:
– port type - The operations performed by the
web service.
– message - The messages used by the web
service.
– types - The data types used by the web
service.
– binding - The communication protocols used
by the web service.
WSDL Document
<message name="GetStockPriceRequest">
<part name="stock" type="xs:string"/>
</message>
<message name="GetStockPriceResponse">
<part name="value" type="xs:string"/>
</message>
<portType name=“StocksRates">
<operation name=“GetStockPrice">
<input message=“GetStockPriceRequest"/>
<output message=“GetStockPriceResponse"/>
</operation>
</portType>
UDDI
• UDDI stands for Universal Description,
Discovery and Integration.
• UDDI is a directory for storing
information about web services , like
yellow pages.
• UDDI is a directory of web service
interfaces described by WSDL.
Web Services Technologies
• Other implementation of JAX-RPC and/or
Java-based web services
– Apache Axis
– IBM WebSphere
• Microsoft support for web services: .NET
• PHP also has web services tools
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved. 0-13-185603-0