WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
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\Axis2StubHello.java:
/** * Axis2StubHello.java * Copyright (c) 2009 by Dr. Herong Yang, 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 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 stub._getServiceClient().getOptions() .setProperty(HTTPConstants.CHUNKED,false); // 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(); out.println(output); } catch (Exception e) { e.printStackTrace(); } } }
Compilation and execution of this program are described below:
C:\herong>cd axis2\src C:\herong\axis2\src>\local\jdk\bin\javac -Djava.ext.dirs=\local\axis2\lib\ Axis2StubHello.java C:\herong\axis2\src>\local\jdk\bin\java -Djava.ext.dirs=\local\axis2\lib\ Axis2StubHello Hello from server - herongyang.com.
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
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
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
Generating Client Side Stub Java Code
►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