WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
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="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:hy="http://www.herongyang.com/Service/" targetNamespace="http://www.herongyang.com/Service/"> <wsdl:documentation> Hello_WSDL_11_SOAP.wsdl Copyright (c) 2007 by Dr. Herong Yang, herongyang.com All rights reserved </wsdl:documentation> <wsdl:types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.herongyang.com/Service/"> <xsd:element name="HelloRequest" type="xsd:string"/> <xsd:element name="HelloResponse" type="xsd:string"/> </xsd:schema> </wsdl:types> <wsdl:message name="helloInputMessage"> <wsdl:part name="helloInputPart" element="hy:HelloRequest"/> </wsdl:message> <wsdl:message name="helloOutputMessage"> <wsdl:part name="helloOutputPart" element="hy:HelloResponse"/> </wsdl:message> <wsdl:portType name="helloPortType"> <wsdl:operation name="Hello"> <wsdl:input name="helloInput" message="hy:helloInputMessage"/> <wsdl:output name="helloOutput" message="hy:helloOutputMessage"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="helloBinding" type="hy:helloPortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="Hello"> <soap:operation soapAction="http://www.herongyang.com/Service/Hello"/> <wsdl:input name="helloInput"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="helloOutput"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="helloService"> <wsdl:port name="helloPort" binding="hy:helloBinding"> <soap:address location="http://www.herongyang.com/Service/Hello_SOAP_11.php"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
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, HelloServiceStub.java, 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\HelloServiceStub.java.
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