Transcript PowerPoint

SSC2: Web Services
Web Services




Web Services offer interoperability using the
web
Web Services provide information on the
operations they can perform
Clients can be built using this information,
and coupled to any interface
Natural extension of OOP
Uses of Web Services

To ‘glue’ together components of a
system, especially distributed
computing



MOBIlearn
mobile gaming
To provide standardised access to
databases, services etc

Amazon
Important elements

SOAP


UDDI



The XML messaging protocol that all web services
use
A directory service for locating Web Services
Built in to .NET
WSDL

XML document describing what a web service can
do
Linux
Java
PDA
.NET
Web Service
HTTP
XML
Server
PHP
Windows
C++
XML

Plain text mark-up

Strict syntax

Flexible vocabulary

Supports schemas
XML example
<books source="Pete's Bookshelf">
<book>
<author type="single author">
<lastname>Heller</lastname>
<firstname>Joseph</firstname>
</author>
<title>Catch 22</title>
<publisher>Macmillan</publisher>
<isbn number="010176483933" />
</book>
<book>
<author type="primary author">
<lastname>Preece</lastname>
<firstname>Jenny</firstname>
</author>
<author type="secondary author">
<lastname>Rogers</lastname>
<firstname>Yvonne</firstname>
</author>
<author type="secondary author">
<lastname>Sharp</lastname>
<firstname>Helen</firstname>
</author>
<title>Human Computer Interaction</title>
<publisher>Addison Wesley</publisher>
<isbn number="8575689937334" />
</book>
</books>
XML schemas


Describe the expected structure of an
XML document
Books example
XML and Web Services



Web Services were envisaged as a way
to allow different platforms, languages,
systems etc to communicate using a
standardised language
Not just communicate, but perform
actions
XML & schemas provide this language
SOAP

SOAP: Simple Object Access Protocol

Plain text XML transmitted using HTTP

Sent using GET and POST, instead of HTML

Allows sending of text/XML data


workaround allows sending of binary files e.g.
images, by sending byte array
can also use SOAP with Attachments
Summary



A Web Service is a web application that has
some of its methods accessible over the web
Clients can retrieve a structured document
giving details about how those methods
should be called, and what they will return
All done over HTTP/XML/SOAP
Axis



Apache Axis is a web application for
deploying and consuming web services
using Java
Runs as an application under Tomcat
Allows Java methods to be ‘exposed’ as
web service methods
Axis tools



Axis comes with a number of useful
tools for working with WSDL, XML etc
We can call them from the command
line, but we need all the required
libraries in our classpath
So we can call them from a project
inside NetBeans instead
Setting up Axis

Axis is a web application that runs under
Tomcat

Copy the ‘axis’ folder from J: to your work
folder


Create a new Web Application within
NetBeans, using existing sources, with Axis as
the source
Add new classes to your Axis application
Deployment

Axis lets us deploy web services in 2
ways:



instantly, using .jws files that are deployed
at runtime
using a deployment config file to specify
which classes and methods to expose
Instant method is great for quick &
easy web services, but doesn’t allow
the use of other Java packages
Data types














xsd:base64Binary
xsd:boolean
xsd:byte
xsd:dateTime
xsd:decimal
xsd:double
xsd:float
xsd:hexBinary
xsd:int
xsd:integer
xsd:long
xsd:Qname
xsd:short
xsd:string
byte[]
Boolean
Byte
java.util.Calendar
java.math.BigDecimal
Double
Float
byte[]
Int
java.math.BigInteger
Long
javax.xml.namespace.Qname
Short
java.lang.String
Returning sets of results


Often we want to send/receive sets of
data of with varying number of
elements
3 basic methods:



concatenate the results into a single string
return an array (of strings, integers etc)
return a structured XML document
Consuming Web Services


Any platform that can parse & generate
SOAP requests can communicate with a
Web Service
Tools that generate code stubs from
WSDL documents make it easy
Consuming with Axis


Axis tool WSDL2Java generates code
stubs from WSDL document
Can use stubs to create ‘proxy’ classes
that act as local versions of the web
service, making calls to the actual
service when necessary
Consuming with Axis
User
Interface
Client
side
Web
Service
classes
Local
classes
Server
side
Axis
web app
Proxy
classes
HTTP
SOAP
Tomcat
server
Understanding Scope

Scope determines how often a servlet or web
service gets loaded:



Request: a new instance is created for every
request that is received
Session: a new instance is created for each user’s
session
Application: a new instance is created each time
the application is started
Issues




Web Services only offer content pull
Even with WSDL, ambiguity can arise because of
interpretation
XML might be difficult to parse, depending on
methods used
Not all implementations of SOAP are the same



eg Infinity vs Inf
Date/Time formats
Trailing zeroes in decimals 0.70 vs 0.7