Web Service
C. Edward Chow
Related reference: Based on Part 1 of IBM Red Book
WebSphere Version 6
Web Services Handbook
Development and Deployment by Ueli Wahli et al
J2EE14 Tutorial
cs301 1 chow
Motivation for Service Oriented
Architecture (SOA)
There is an increase trend for sharing resource/data both within
companies and among companies in a flexible/standardized
manner.
In a service oriented approach, the complete value chain within the
company is divided into small modular functional units, or services.
A service oriented architecture focus on how services are described
and organized to support the dynamic, automated discovery and
use.
Companies and their sub-units should be able to easily provide
services. Other business units can use these services in order to
implement their business processes.
cs301 2 chow
Service-Oriented Architecture
Consists of three basic components:
Service provider
Service broker (aka service registry)
Service requestor
cs301 3 chow
Requirements of SOA
Interoperability between different systems and
programming languages. (Use standards; platform
independent)
Clear and unambiguous description language
Retrieval of the service
Security
cs301 4 chow
What is Web Services
“A Web Service is a software component that is described via
WSDL and is capable of being accessed via standard network
protocols such as but not limited to SOAP over HTTP”---www.oasis-
open.org/committees/wsia/glossary/wsia-draft-glossary-03.htm
Web services are self-contained, modular applications that can be
described, published, located, and invoked over a network –IBM
Redbook.
The Web technologies used:
XML (Extensible Markup Language)
SOAP (Simple Object Access Protocol) allow client to call
remote service. The msg format is XML.
WSDL (Web Services Description Language)
WSIL (Web Services Inspection Language)
UDDI (Universal Description, Discovery, and Integration) a
standard used for publishing/query web services
Web Services can be used to realized service oriented architecture.
cs301 5 chow
Short History of Web Services
HTTP protocol facilitates Human-to-Application (H2A) communications.
There is an increasing demand for Application-to-Application
communication using existing techniques.
HTTP is not adequate for more complex operations. E.g., remote operation
Late 1999, Microsoft published SOAP an XML-based protocol.
IBM supports SOAP early 2000.
May 2000 W3C Note: SOAP 1.1.
The term Web services was coined several months later, when IBM,
Microsoft, and Ariba jointly published the Web Services Description
Language (WSDL).
March 2001 W3C Note: WSDL1.1
2002, UDDI 1.0 (API 6/28; UDDI v1.0 XML schema; WSDL Service
Interface Description: UDDI Inquire API/UDDI Publish API) were also
introduced, thus completing the set of standards and protocols that make
up the basis of Web services.
cs301 6 chow
Current Web Service Standards
9/19/2005 Web Services Description Language (WSDL)
Version 2.0 Part 0: Primer (Last Call Working Draft;
review period ends 19 September 2005)
2/3/2005 UDDI v3.0 Ratified as OASIS standard.
June 2003: SOAP Version 1.2 released as a W3C
Recommendation
11/9/2005: Oasis Web Service Security (WSS)1.1
proposed draft. Address Quality of Service (QoS) and
Security issues.
There are more than 40 specifications and standards
published!
cs301 7 chow
SOA based on Web Services
cs301 8 chow
How Web Services Are Being Used?
Military/Defense Contractors are integrated subsystems
using web services. Wrap around legacy system with
existing applications such as satellite control, image
delivery.
Web Services/SOA on Wall Street
Good collection of Speaker presentations
Insurance Industry:
cs301 9 chow
Opportunity for Web Services
An Insurance Model by M. Bhaskar WIPRO
cs301 10 chow
Building a Simple Web Service with
JAX-RPC
JAX-RPC: Java API for XML-based RPC (Remote
Procedure Call)
We will the tools and Sun Application Server provided
by j2eesdk-1_4_02_2005Q2 for this simple demo.
RPC is used in distributed client server model for client
to execute procedures on other systems.
In JAX-RPC, RPC is realized by XML-based SOAP
(Simple Object Access Protocol)
SOAP specifies the envelop structure, encoding rules,
convention for representing RPC and response.
These calls are transmitted as SOAP messages over
HTTP.
cs301 11 chow
Software Module in JAX-RPC based
Web Service
A stub is a small program routine that substitutes for a longer program,
possibly to be loaded later or that is located remotely.
Here it accepts request from HelloClient, forwards requests to HelloServie
through the help JAX-RPC Runtime, and receives/returns responses.
Tie classes are used by HelloService to communicate with clients.
cs301 12 chow
How to Develop a Web Service
Start by defining Service Endpoint Interface (SEI).
SEI is a Java interface that declares the methods a
client can invoke on the web service.
With j2eesdk, we use wscompile tool, SEI, and two
configuration files to generate WSDL specification of the
web service and stubs that connect a web service client
to the JAX-RPC runtime.
cs301 13 chow
Basic Steps for Creating Web Service
and client:
1. Code the SEI and implementation class and interface configuration
file.
2. Compile the SEI and implementation class.
3. Use wscompile to generate the files required to deploy the service.
4. Use deploytool to package the files into a WAR file.
5. Deploy WAR file. The tie classes are generated by the Application
Server during the deployment.
6. Code the client class and WSDL configuration file.
7. Use wscompile to generate and compile the stub files.
8. Compile the client class.
9. Run the client
cs301 14 chow
1. Code the SEI and implementation class
package helloservice;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface HelloIF extends Remote {
public String sayHello(String s) throws RemoteException;
}
package helloservice;
public class HelloImpl implements HelloIF {
public String message ="Hello";
public String sayHello(String s) {
return message + s;
}
}
cs301 15 chow
Setup your build.properties file
In the j2eetutorial14 tutorial directory, under common
subdirectory, there is a build.properties file that allow
one to specify asant related build info.
The first property is j2ee.home which we need to
specifies the j2ee application server installation directory
The 2nd property we specify where is the tutorial
directory.
j2ee.home=/.automount/cs/root/usr2/students/cs301/SU
NWappserver
j2ee.tutorial.home=/.automount/cs/root/usr2/students/cs
301/public_html/j2ee/j2eetutorial14
cs301 16 chow
Build the Service
windom.uccs.edu> cd /j2eetutorial14/examples/jaxrpc/helloservice
windom.uccs.edu> asant build
Buildfile: build.xml
j2ee-home-test:
init:
prepare:
[echo] Creating the required directories....
[mkdir] Created dir:
/.automount/cs/root/usr2/students/cs301/public_html/j2ee/j2eetutorial14/examples/ja
xrpc/helloservice/build
compile-service:
[echo] Compiling the server-side source code....
[javac] Compiling 2 source files to
/.automount/cs/root/usr2/students/cs301/public_html/j2ee/j2eetutorial14/examples/ja
xrpc/helloservice/build
generate-wsdl:
j2ee-home-test:
init:
cs301 17 chow
Compile Service/Generate-wsdl Tasks
Asant build create build directory and execute compile-service and
generate-wsdl tasks.
compile service just compile HelloIF.java and HelloImpl.java
Generate-wsdl task creates MyHelloService.wsdl and mapping.xml
files.
It runs the followings wscompile command:
wscompile -define -mapping build/mapping.xml -d build -nd build -
classpath build config-interface.xml
Wecompile also read in the config-interface.xml, it specifies the
service name, namespace, package and interface name.
.wsdl file describes the Web service and is used to generate client
stubs.
The mapping.xml file contains info that correlates the mapping
between the Java interface and the WSDL definition.
cs301 18 chow
Packaging the Service
JAX-RPC Web service is implemented as servlet.
New Web Component wizard of Deploytool can be used
to package the service.
The wizard will
Create web application deployment descriptor
Create a WAR file
Add the DD and service files to WAR file.
cs301 19 chow
Specify the Endpoint Address
Client will access MyHelloService with
http://localhost:8080/hello-jaxrpc/hello
We need specify this url mapping using deploytool.
Deploytool
Select general tab
Enter /hello-jaxrpc in the ContextRoot field
In the tree, select HelloImpl
Select alias tab, ad /hello in Compoent Alias table
In Endpont tab, select hello for Endpoint Address in
Sun-specific setting frame.
Select File | save
cs301 20 chow
Deploying the Service
Deploytool
Select MyHelloService in the tree
Select Tools | Deploy
After installed, we can view WSDL file of this web
service with
http://localhost:8080/hello-jaxrpc/hello?WSDL from a
web browser.
cs301 21 chow
Static Stub Client
HelloClient is a stand-alone program that call sayHello method of
the MyHelloService.
It makes call through a stub, a local object that acts as a proxy for
the remote service.
It is called static stub since the stub was created by wscompile at
development time (not run time).
There are three other types of clients
Dynamic Proxy (call through this classes thatis created in
runtime)
Dynamic Invocation Interface (DII)
(can call a rpc even if the service name is unknown until
runtime)
Application Client (as opposed to standalone clients above).
Here we can locate web service through JNDI lookup.
cs301 22 chow
package staticstub;
import javax.xml.rpc.Stub;
public class HelloClient {
private String endpointAddress;
HelloClient.java
public static void main(String[] args) {
System.out.println("Endpoint address = " + args[0]);
try {
Stub stub = createProxy();
stub._setProperty
(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
args[0]);
HelloIF hello = (HelloIF)stub;
System.out.println(hello.sayHello("Duke!"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static Stub createProxy() {
// Note: MyHelloService_Impl is implementation-specific.
return
(Stub) (new MyHelloService_Impl().getHelloIFPort());
}
}
cs301 23 chow
Building/Running Static Stub Client
cd /j2eetutorial14/examples/jaxrpc/staticstub/
asant build
This invokes three tasks
Generate-stub
Compile-client
Package-client
asant run
Hello Duke!
cs301 24 chow
Generate-stubs
It executes the following cmd:
wscompile -gen:client -d build -classpath build config-
wsdl.xml
-gen:client generate stubs, other runtime (serializers)
The config-wsdl.xml contains
It tells wscompile where to get the WSDL specification file.
cs301 25 chow