Using Stub and Data Type Classes

This section provides a tutorial example on how to use stub and data type classes to invoke a Web service. Using the stub class is simpler than using the generic ServiceClient class.

Ok. I think I am ready to write a client program to use stub and data type classes generated from Hello_WSDL_11_SOAP.wsdl by WSDL2Java, .\axis2\src\

 * Copyright (c) 2009 by Dr. Herong Yang,
 * All rights reserved
import com.herongyang.www.service.*;
import com.herongyang.www.service.HelloServiceStub.*;
import org.apache.axis2.transport.http.*;
class Axis2StubHello {
   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

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

// Calling the operation
         HelloResponse response = stub.Hello(request);

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

      } catch (Exception e) {

Compilation and execution of this program are described below:

C:\herong>cd axis2\src


   -Djava.ext.dirs=\local\axis2\lib\ Axis2StubHello

      Hello from server -

Congratulations! The first stub program worked nicely. The only extra step I added in the program is ...setProperty(HTTPConstants.CHUNKED,false), which is needed to fix the Length Required error.

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