WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
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 failed loading WSDL 2.0 document with the ServiceClient class, I tried to use Axis2 1.4.1 WSDL2Java command line tool to generate a client stub class from my WSDL 2.0 document with the "-wv 2.0" option:
C:\herong>\local\axis2\bin\wsdl2java -o wsdl2 -d adb -s -wv 2.0 -uri Hello_WSDL_20_SOAP.wsdl Using AXIS2_HOME: \local\axis2 Using JAVA_HOME: \local\jdk C:\herong>dir Wsdl2\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, .\wsdl2\src\Axis2StubHelloWsdl20.java:
/** * Axis2StubHelloWsdl20.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 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 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:
C:\herong>cd wsdl2\src C:\herong\wsdl2\src>javac Axis2StubHelloWsdl20.java C:\herong\wsdl2\src>\local\jdk\bin\javac -Djava.ext.dirs=\local\axis2\lib\ Axis2StubHelloWsdl20.java C:\herong\wsdl2\src>\local\jdk\bin\java -Djava.ext.dirs=\local\axis2\lib\ Axis2StubHelloWsdl20 Hello from server - herongyang.com.
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
ServiceClient Class Loading WSDL 2.0 Documents
► WSDL2Java Converting WSDL 2.0 Documents to Stub Classes
WSDL 2.0 Component Model - Test
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
WSDL 1.1 Binding Extension for SOAP 1.2
WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles