22
SSC2: Web Services

SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

Embed Size (px)

Citation preview

Page 1: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

SSC2: Web Services

Page 2: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 3: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 4: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

Important elements SOAP

The XML messaging protocol that all web services use

UDDI A directory service for locating Web Services

Built in to .NET

WSDL XML document describing what a web service can do

Page 5: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

Web ServiceHTTPXML

WindowsC++

LinuxJava

PDA.NET

ServerPHP

Page 6: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

XML

Plain text mark-up

Strict syntax

Flexible vocabulary

Supports schemas

Page 7: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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>

Page 8: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

XML schemas

Describe the expected structure of an XML document

Books example

Page 9: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 10: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 11: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 12: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 13: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 14: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 15: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 16: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

Data types xsd:base64Binary byte[] xsd:boolean Boolean xsd:byte Byte xsd:dateTime java.util.Calendar xsd:decimal java.math.BigDecimal xsd:double Double xsd:float Float xsd:hexBinary byte[] xsd:int Int xsd:integer java.math.BigInteger xsd:long Long xsd:Qname javax.xml.namespace.Qname xsd:short Short xsd:string java.lang.String

Page 17: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 18: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 19: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 20: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

Consuming with Axis

UserInterface

Localclasses

Proxyclasses

Tomcatserver

Axisweb app

WebServiceclasses

Clientside

Serverside

HTTPSOAP

Page 21: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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

Page 22: SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform

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