WSDL2Java Converting WSDL 2.0 Documents to Stub Classes

This section provides a tutorial example how to use WSDL2Java to generate a client stub class from a WSDL 2.0 document.

After loading WSDL 2.0 document with the ServiceClient class, I tried to use Axis2 WSDL2Java command line tool to generate a client stub class from my WSDL 2.0 document with the "-wv 2.0" option:

herong> set JAVA_HOME=\Progra~1\java\jdk-10.0.1

herong> set AXIS2_HOME=\local\axis2

herong> \local\axis2\bin\wsdl2java -uri Hello_WSDL_20_SOAP.wsdl \
   -o HelloWsdl20 -d adb -s -wv 2.0

Using AXIS2_HOME:   \local\axis2
Using JAVA_HOME:    \Progra~1\java\jdk-10.0.1
log4j:WARN No appenders could be found for logger
   (org.apache.axis2.description.WSDL20ToAxisServiceBuilder).
log4j:WARN Please initialize the log4j system properly.
...

herong> dir HelloWsdl20\src\com\herongyang\www\service
            51,608 HelloServiceStub.java

Good. The stub class generation was successful. Here is Java program to test the stub class, .\HelloWsdl20\src\Axis2StubHelloWsdl20.java:

/* Axis2StubHelloWsdl20.java
 * Copyright (c) 2009 HerongYang.com. All Rights Reserved.
 */
import java.io.PrintStream;
import com.herongyang.www.service.*;
import com.herongyang.www.service.HelloServiceStub.*;
import org.apache.axis2.transport.http.*;
class Axis2StubHelloWsdl20 {
   public static void main(String[] args) {
      PrintStream out = System.out;
      try {

// Creating the stub
         HelloServiceStub stub = new HelloServiceStub();

// Fixing org.apache.axis2.AxisFault: Transport error:
//    411 Error: Length Required
         stub._getServiceClient().getOptions()
            .setProperty(HTTPConstants.CHUNKED,false);

// Building the input parameter
         Hello request = new Hello();
         request.setHello("Hello from Stub client.");

// Calling the operation
// Calling the operation
//    Method name is operation name in lower case in Axis2 1.7.8
//    Method name is operation name in Axis2 1.4.1
//         HelloResponse response = stub.Hello(request);
         HelloResponse response = stub.Hello(request);

// Retrieving output parameter
         String output = response.getHelloResponse();
         out.println(output);

      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

The execution result was good too:

herong> cd HelloWsdl20\src

herong\HelloWsdl20\src> javac -cp .;\local\axis2\lib\* \
   com\herongyang\www\service\HelloServiceStub.java


herong\HelloWsdl20\src> javac -cp .;\local\axis2\lib\* \
   Axis2StubHelloWsdl20.java


herong\HelloWsdl20\src> java -cp .;\local\axis2\lib\* \
   Axis2StubHelloWsdl20

      Hello from server - herongyang.com.

Cool. wsdl2java command from Apache Axis2/Java 1.7.8 also support WSDL 2.0 documents!

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

Using WSDL Document in Java Apache Axis2/Java for WSDL

 What Is Axis2

 Downloading and Installing Axis2/Java

 org.apache.axis2.client.ServiceClient Class

 Creating Service Client with WSDL Document

WSDL2Java Converting WSDL 2.0 Documents to Stub Classes

 Apache Woden for WSDL Documents in Java

 SoapUI - Web Service Testing Tool

 PHP SOAP Extension for WSDL

 Perl SOAP::Lite for WSDL

 Introduction to WSDL 1.1

 WSDL 1.1 Document Structure and Syntax

 WSDL 1.1 Binding Extension for SOAP 1.1

 SoapUI as WSDL 1.1 Testing Tool

 WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles

 PHP SOAP Extension for WSDL 1.1

 Perl SOAP::Lite for WSDL 1.1

 Apache Axis2/Java for WSDL 1.1

 Using WSDL2Java to Generate Web Service Stub Classes

 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

 Python SOAP Client: Zeep

 WSDL Related Terminologies

 Archived Tutorials

 References

 Full Version in PDF/EPUB