Generating Client Side Stub Java Code

This section provides a tutorial example on how to run WSDL2Java to generate client side stub Java code from an existing WSDL document. The generated stub class will have a package name borrowed from the target namespace of the Web service.

To use WSDL2Java, I need to have Axis2 installed on my Windows system. See other tutorials in this book for downloading and installing Axis2 1.4.1.

To test SDL2Java, I wrote this simple WSDL document, Hello_WSDL_11_SOAP.wsdl:

<?xml version="1.0"?>
<wsdl:definitions xmlns:wsdl=""

    Copyright (c) 2007 by Dr. Herong Yang,
    All rights reserved

    <xsd:schema xmlns:xsd=""
      <xsd:element name="HelloRequest" type="xsd:string"/>
      <xsd:element name="HelloResponse" type="xsd:string"/>

  <wsdl:message name="helloInputMessage">
    <wsdl:part name="helloInputPart" element="hy:HelloRequest"/>
  <wsdl:message name="helloOutputMessage">
    <wsdl:part name="helloOutputPart" element="hy:HelloResponse"/>

  <wsdl:portType name="helloPortType">
    <wsdl:operation name="Hello">
      <wsdl:input name="helloInput"
      <wsdl:output name="helloOutput"

  <wsdl:binding name="helloBinding" type="hy:helloPortType">
    <soap:binding transport=""/>
    <wsdl:operation name="Hello">
      <wsdl:input name="helloInput">
        <soap:body use="literal"/>
      <wsdl:output name="helloOutput">
        <soap:body use="literal"/>

  <wsdl:service name="helloService">
    <wsdl:port name="helloPort" binding="hy:helloBinding">


Then I used to following commands to generated client side Java classes with WSDL2Java:

C:\herong>set JAVA_HOME=\local\jdk

C:\herong>set AXIS2_HOME=\local\axis2

C:\herong>\local\axis2\bin\wsdl2java -uri Hello_WSDL_11_SOAP.wsdl 
   -o axis2 -d adb -s
Using AXIS2_HOME:   \local\axis2
Using JAVA_HOME:    \progra~1\java\jdk
Retrieving document at 'Hello_WSDL_11_SOAP.wsdl'.

The WSDL2Java command line options I used are:

The generated class code is stored in a single Java class,, in a package named after the target name space, com.herongyang.www.service. The class file is located at: .\axis2\src\com\herongyang\www\service\

Last update: 2009.

Table of Contents

 About This Book

 Introduction to WSDL 2.0

 WSDL 2.0 Document Structure and Syntax

 WSDL Version 2.0 Part 2: Adjuncts

 WSDL 2.0 Document Examples with SOAP Binding

 WSDL 20 Programming APIs and Testing Tools

 Introduction to WSDL 1.1

 WSDL 1.1 Document Structure and Syntax

 WSDL 1.1 Binding Extension for SOAP 1.1

 soapUI 3.0.1 - Web Service Testing Tool

 WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles

 PHP SOAP Extension in PHP 5.3.1

 Using WSDL in Perl with SOAP::Lite 0.710

 Using WSDL Document in Java with Axis2 1.4.1

Using WSDL2Java to Generate Web Service Stub Classes

 What Is WSDL2Java?

Generating Client Side Stub Java Code

 Stub and Data Type Classes

 Using Stub and Data Type Classes

 XML Document Based Web Service Example

 "Unexpected subelement ..." Error from the Stub Class

 RPC Method Based Web Service Example

 WSDL 1.1 Binding Extension for SOAP 1.2

 WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles

 SOAP 1.2 Binding - PHP, Java and Perl Clients

 WSDL Related Terminologies


 PDF Printing Version