March 2006
Building web services with Apache Axis
I. Assumptions:
==========
(1) Your path variable contains C:\batch.
(2) C:\batch has the following batch files:
adminclient.bat
java org.apache.axis.client.AdminClient %1
wsdl2java.bat
java org.apache.axis.wsdl.WSDL2Java %1
tcpmon.bat
java org.apache.axis.utils.tcpmon %1
(3) Your classpath includes all of the jar files required by Axis. For
example, the classes AdminClient and WSDL2Java must be
in a jar file pointed to by your classpath.
(4) You have located your Microsoft wsdl.exe file. Mine was found in:
C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\wsdl.exe
(5) You have located your Microsoft command line C# compiler.
Mine was found in:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe
(6) Add the above paths to your path variable. Mine now reads:
C:\Program Files\Java\jdk1.5.0_05\bin;
C:\Program Files\Microsoft.NET\SDK\V1.1\Bin;
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322;
C:\WINDOWS\system32;
C:\batch;
C:\Tomcat 5.5\bin;
%ANT_HOME%\bin;
II. Building a simple web service
======================
1. Create server side Java code:
// SimpleCrypto.java
// On the server side
public class SimpleCrypto {
public int caeser(int c) { return c + 3 % 26; }
}
2. Create server side deployment descriptors. The following deployment
descriptor defines the web service scope as "application". This scope
means that the object will be created once and shared by all users.
The scope value may be changed to "session" or "request". An object
with request scope is created before each call and destroyed after each
call. An object with session scope is associated with a particular client.
When using session scope, your java client will contain the following
code. This tells the client to send along a cookie with each request.
The cookie is used to distinguish between different clients.
SomeWSServiceLocator loc = new SomeWSServiceLocator();
// maintain session
loc.setMaintainSession(true);
Here is the deployment descriptor for an application object.
deploy.wsdd
Here is an undeploy descriptor.
undeploy.wsdd
3. Copy all .class files to C:\Tomcat 5.5\webapps\axis\WEB-INF\classes.
4. Run adminclient deploy.wsdd
5. When done run adminclient undeploy.wsdd.
If you make any changes to the deployment descriptor you may have to stop
and then restart Tomcat for testing.
III. On the client
===========
1. Visit http://localhost:8080/axis/servlet/AxisServlet
and save the wsdl document associated with CaeserService.
2. Place this file on the client side. When writing a microsoft client
you will need to change the extension from ".xml" to ".wsdl".
IV. Client side programming in Java
========================
1. Run wsdl2java CaeserService.xml.
2. Look over the new directory and examine the Java source code
generated.
// Java Client directory
D:\McCarthy\www\95-804\examples\caeser\client>tree /f
Folder PATH listing
Volume serial number is 71FAE346 BA17:BF69
D:.
¦ CaeserClient.class
¦ CaeserClient.java
¦ CaeserService.xml
¦
+---localhost
+---axis
+---services
+---CaeserService
CaeserServiceSoapBindingStub.class
CaeserServiceSoapBindingStub.java
SimpleCrypto.class
SimpleCrypto.java
SimpleCryptoService.class
SimpleCryptoService.java
SimpleCryptoServiceLocator.class
SimpleCryptoServiceLocator.java
3. Write a client in Java.
import localhost.axis.services.CaeserService.*;
public class CaeserClient {
public static void main(String args[]) throws Exception {
SimpleCryptoServiceLocator loc = new SimpleCryptoServiceLocator();
SimpleCrypto s = loc.getCaeserService();
int c = s.caeser(5);
System.out.println(c);
}
}
V. Client side programming in C#
=======================
1. Run wsdl CaeserService.wsdl (note change in extension)
2. Look over the new ".cs" file and examine the source code.
The file is named SimpleCryptoService.cs
3. Compile this into a library.
csc -t:library SimpleCryptoService.cs
producing a SimpleCryptoService.dll
4. Write a C# client.
using System;
public class MyClient {
public static void Main() {
SimpleCryptoService crypto = new SimpleCryptoService();
int c = crypto.caeser(65);
Console.WriteLine(c);
}
}
Compile with
csc -r:SimpleCryptoService.dll Client.cs
VI. Watching the SOAP interactions
======================
1. Run tcpmon from any directory.
2. The client contacts 7070 (proxy code must be changed to 7070) and tcpmon visits 8080 where
Tomcat/Axis is listening