Recently I need to create a client application to get web service with SOAP/HTTP. What I have is just WSDL URI. First I use Eclipse to genearte client program but it only automatically does for Axis 1.4 run time. Then I decide to use JAX-WS 2.0 and WSIT. I list the steps and you can follow it.
1. Download “webservices-tools.jar”
This is a specific task which is part of WSIT implementation of JAX-WS. Check this out
https://jax-ws.dev.java.net/files/documents/4202/65101/wsit-1_0-fcs-bin-b26-31_jul_2007.jar
2. Run Ant to generate stub
[build.xml]
<project name=”weatherServiceClient” basedir=”.”>
<property name=”src” value=”src” />
<property name=”build” value=”build” />
<property name=”dist” value=”dist” />
<path id=”jaxws.classpath”>
<pathelement path=”${classpath}”/>
<pathelement location=”lib/webservices-tools.jar”/>
</path>
<path id=”build.classpath”>
<pathelement path=”${classpath}”/>
<pathelement path=”${build}”/>
</path>
<target name=”generateStub” description=”Generate stub”>
<mkdir dir=”build” />
<mkdir dir=”dist” />
<taskdef name=”wsimport” classname=”com.sun.tools.ws.ant.WsImport”>
<classpath refid=”jaxws.classpath”/>
</taskdef>
<wsimport
debug=”true”
verbose=”true”
keep=”true”
sourcedestdir=”${src}”
extension=”true”
destdir=”${build}”
package=”com.example”
wsdl=”http://www.deeptraining.com/webservices/weather.asmx?WSDL”>
</wsimport>
</target>
<target name=”compileClient” description=”Compile client source”>
<javac destdir=”${build}” debug=”on” deprecation=”on” optimize=”on” classpathref=”build.classpath”>
<src path=”${src}” />
</javac>
</target>
<target name=”runClient” description=”Run client”>
<java classname=”com.example.WeatherServiceClient” fork=”true”>
<arg value=”New York”/>
<classpath>
<pathelement location=”${build}”/>
</classpath>
</java>
</target>
<target name=”jarIt”>
<jar jarfile=”${dist}/${ant.project.name}.jar” basedir=”build” />
</target>
<target name=”runClientWithJar” description=”Run client with jar”>
<java classname=”com.example.WeatherServiceClient” fork=”true”>
<classpath>
<pathelement location=”${dist}/${ant.project.name}.jar”/>
</classpath>
</java>
</target>
<target name=”clean” description=”Cleanup”>
<delete dir=”${dist}” />
<delete dir=”${build}” />
</target>
</project>
[command]
c:\Temp\myjaxws-examples>ant generateStub
3. Compile “WeatherServiceClient”
[WeatherServiceClient.java]
package com.example;
public class WeatherServiceClient {
private static String CITY = “Paris”;
public static void main(String args[]) {
if (args.length>0 && args[0] != null){
CITY = args[0];
}
WeatherSoap wsp = new Weather().getWeatherSoap();
String forecast = wsp.getWeather(CITY);
System.out.println(CITY + “’s weather forecast=” + forecast);
}
}
[Command]
c:\Temp\myjaxws-examples>ant compileClient
4. Run “WeatherServiceClient”
c:\Temp\myjaxws-examples>ant runClient
5. jar command
c:\Temp\myjaxws-examples\dist>java -cp .;dis\weahterServiceClient.jar com.example.WeatherServiceClient
6. Structure:
-temp
+myjaxws-examples
-build.xml
+lib
-webservices-tools.jar
+build
-Weather.class
-WeatherServiceClient.class
…
+src
-Weather.java
-WeatherServiceClient.java
+dist
-WeatherServiceClient.jar
7. Reference:
Web Services Made Easy with JAX-WS 2.0





