Creating stand alone WebService Client from WSDL

The below post provides an implementation of a Java stand alone client for a sample Java WebService.  All you need to know is the URL to its public contract file, or WSDL.


A WSDL file, describing the WebService deployed on the Server.

You can refer the below link to create a WebService in WebLogic.

Please follow the below steps to generate a standalone WebService client  using ant script.

1.  Setting up the Environment:

Open a command prompt and set the classpath by running the under the domain directory.

2. Create Ant Script:

Create a standard ant script with the clientgen ant task.

The clientgen WebLogic Web Service Ant task to generate the artifacts that your client application needs to invoke the Web Service operation. These artifacts include:

  • The Java class for the Service interface implementation for the particular Web Service you want to invoke.
  • JAXB data binding artifacts.
  • The Java class for any user-defined XML Schema data types included in the WSDL file.

A definition of clientgen is as below.

<taskdef name=”clientgen”
classname=”” />

A sample snippet of clientgen ant task would like below.






The clientgen Ant task uses the WSDL of the deployed HelloWorldService Web Service to generate the necessary artifacts and puts them into the output/clientclassdirectory, using the specified package name.

A complete ant task looks like below.



<project name="webservices-simple_client" default="all">

<!-- set global properties for this build -->

<property name="wls.hostname" value="localhost" />

<property name="wls.port" value="7001" />

<property name="example-output" value="output" />

<property name="clientclass-dir" value="${example-output}/clientclass" />

<path id="client.class.path">

<pathelement path="${clientclass-dir}"/>

<pathelement path="${java.class.path}"/>


<taskdef name="clientgen"

classname="" />

<target name="clean" >

<delete dir="${clientclass-dir}"/>


<target name="all" depends="clean,build-client,run" />

<target name="build-client">







srcdir="${clientclass-dir}" destdir="${clientclass-dir}"



srcdir="." destdir="${clientclass-dir}"



<target name="run" >

<java fork="true"


failonerror="true" >

<classpath refid="client.class.path"/>






4.  Create the client specific artifacts:

Create client specific artifacts by running the below ant command

ant build-client

This would generate the client specific files under the output/clientclasses folder.

5. Create a Java client:

Create a java standalone client to access the WebService deployed using the client artifacts generated by the clientgen utility.

A sample client would look like below.



package com.test.webservice.client;

import com.test.webservice.client.*;

public class Main {

public static void main(String[] args) {

com.test.webservice.client.HelloWorldService service = new com.test.webservice.client.HelloWorldService();

com.test.webservice.client.HelloWorldPortType port = service.getHelloWorldPortTypePort();

String result=port.sayHelloWorld(" Anandraj ");

System.out.println("***RESULT from WebService ***");







6. Compile and execute the java client and you can see that it is displaying the response from the WebService.

javac -d .

java com.test.webservice.client.Main

For further reading:

Downloads :




Wonders Team.

Latest Comments

  1. Binh Thanh Nguyen January 16, 2016

Leave a Reply