Transcript PPT, 488 KB
EuroFIR Web Services
General introduction to Web
services and an implementation
example
Karl Presser
Agenda
1. History and background of Web services
2. WS Components
• SOAP
• WSDL
• UDDI
3. REST and Mashups
4. An example using Apache AXIS
History and Background
The original purpose of HTTP was to provide a way
to publish and retrieve hypertext pages over the
internet
Browser
Web Server
Middleware
Application server
user program
DB
History and Background
Business to Business
Security
Internet
Firewall
Firewall
Only port 80
Web Server
Web Server
Middleware
Application server
User program
Already
implemented
DB
Only port 80
Client
stub
Remote
Procedure
Call (RPC),
CORBA or
DCOM
Not local
directory
Middleware
Application server
User program
Server
stub
DB
Already
implemented
History and Background
The idea of Web Services
Client
Stub
Wrapping system
internet
Wrapping system
Stub
Server
• use existing software systems
• use port 80/25 to get through all
firewalls
• use a standard representation
schema, e.g. xml
• make it platform independent
• make it programming language
neutral
• construct it modularly for reuse
• make it secure, reliable,
transactional and …
WS Components
Service
registry
find
Service
requester
publish
Service
description
bind
Service
provider
Service description
Service interface
Service
• SOAP (simple object access
protocol) as transport protocol
• WSDL (web service description
language)
• UDDI (universal description and
discovery protocol)
SOAP
Client
Stub, runtime
service location
SOAP system
Serialized
XML Doc
Wrap doc in
HTTP Post
request
HTTP
support
(web client)
Stub, runtime
adapters
SOAP system
Serialized
XML Doc
Wrap doc in
HTTP Post
request
HTTP
support
(web client)
call
Server
do()
INTERNET
SOAP as RPC mechanism
SOAP
SOAP is …
•
•
•
•
•
•
a message construct: A message format
for communication using XML
a processing model: Rules for SOAP
message
a extensibility model: How to extend basic
massages with specific information
a protocol binding framework: Allow
different protocols like HTTP or SMTP
a convention on how to turn a RPC all into
a SOAP message und vise versa
Language independent
Envelope
Header
Header block
Header Block
Body
Body element
WSDL
•
•
•
•
•
•
Describes the interface of a Web service
using XML schema
The types used in the service model
The messages for communication
The operations
The mapping to transport protocols
The location of the service provider
<element name =“food” type = tns:foodType”/>
<complexType name=“foodType”>
<all>
<element name=“id” type=“int”/>
<element name=“name” type=string”/>
…
</complexType>
<operation name="GetFood" pattern=“…"> <input
messageLabel="GetMsg"
element="tns:request"/>
<output messageLabel="SuccessfulMsg"
element="tns:food"/> </operation>
<binding name="RESTfulInterfaceHttpBinding"
interface="tns:RESTfulInterface"
type="http://www.w3.org/ns/wsdl/http"> …/>
>endpoint adress= “…”…/>
UDDI
Originally, UDDI was build as an “Universal Business Registry”
similar to a search engine like Google.
It contains
• business information like the name of the company
• business service offered by the company
• bindingTemplate which are technical information of the service
• tModel which can be used for additional information e.g.
conditions for using the Web service
WS Standards and Spec
REST and Mashups
•
•
•
•
•
REST is a collection of network
architecture principles. It is used to
describe interfaces which transmit
domain-specific data over HTTP without
further detail about the messaging layer
Application state and functionality are
provided using resources
Every resource is uniquely addressable
REST is stateless -> no need to store
information
For processes where a lot of context
information is needed, the REST-url is
getting longer and longer
Procedures:
getUser()
addUser()
removeUser()
updateUser()
REST examples:
http://example.com/users/
http://example.com/users/karl
userResource = new
Resource('http://example.com/user
s/karl')
userResource.delete()
REST and Mashups
A Mashups is web application that combines data from more than one source
into a new web service.
An example is the Chicago Police Department which has a Mashup that
integrates their department’s database of reported crimes with Google
Maps.
Apache Axis
Apache Axis is an implementation of the SOAP submission to W3C. It is a
Java library that helps you to implement all tasks around SOAP and the
installation on Apache AXIS is quite simple.
The following example shows simplified the steps that are needed:
1. Take a java class (food_apple) and write your methods:
public String food() {
String s = “apple”;
return s;
}
public long time() {
return System.currentTimeMillis();
}
Apache Axis
2. Generate the WSDL file using Java2WSDL :
javac food_apple
java org.apache.axis.wsdl.Java2WSDL –o food_apple.wsdl …
food_apple
3. Generate the stub files using WSDL2Java:
java org.apache.axis.wsdl.WSDL2Java … food_apple.wsdl
As a result you find food_appleService.java,
food_appleSoapBindingSkeleton.java, food_appleBindingImpl.java,
food_apple.wsdd and food_apple.java
which are used on the server side.
food_appleServiceLocator.java, food_appleSoapBindingStub.java and
food_apple.java
which are used on the client side.
Apache Axis
4. Copy your method from step 1 into the file
food_appleSoapBindingImpl.java
5. Compile all files
javac *.java
6. Deploy the web service using AXIS AdminClient
java org.apache.axis.client.AdminClient … deploy.wsdd
7. Write the client using
food_appleServiceLocator l= new food_appleServiceLocator();
food_appleSoapBindingStub stub = l.getfood_apple():
System.out.println(stub.food());
System.out.println(stub.time());
Thanks for your attention