XML Document Based Web Service Example

This section provides a tutorial example on how to use stub and data type classes generated by WSDL2Java to invoke an XML document based Web service.

The Web service used in the previous tutorial example was very simple. So let's try a harder one in this tutorial example.

The WSDL document is located at http://www.herongyang.com/Service/ Registration_WSDL_11_SOAP_11_Document.wsdl, which defines is an XML document based Web service with sub elements and attributes required for the SOAP Body element.

Step 1 is to generate stub and data type classes using WSDL2Java:

C:\herong>\local\axis2\bin\wsdl2java -uri http://www.herongyang.com
   -o axis2 -d adb -s

Step 2 is to write a test program in the .\axis2\src folder:

C:\herong>cd axis2\src

C:\herong\axis2\src>type Axis2StubRegistration.java
 * Axis2StubRegistration.java
 * Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
 * All rights reserved
import java.io.*;
import java.util.*;
import com.herongyang.www.service.*;
import com.herongyang.www.service.RegistrationServiceStub.*;
import org.apache.axis2.transport.http.*;
class Axis2StubRegistration {
   public static void main(String[] args) {
      PrintStream out = System.out;
      try {

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

// Fixing org.apache.axis2.AxisFault: Transport error: 
//    411 Error: Length Required

// Building the input parameter
         RegistrationRequest request = new RegistrationRequest();
         request.setDate(new Date());

         String[] guests = new String[2];
         guests[0] = "Herong Yang";
         guests[1] = "John Smith";

// Calling the operation
         RegistrationResponse response = stub.Registration(request);

// Retrieving output parameter
         Confirmation_type0[] confirmation = response.getConfirmation();
         out.println(confirmation[0].getEvent()+": "
         out.println(confirmation[1].getEvent()+": "

      } catch (Exception e) {

Step 3 is to compile and run the test program:



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

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException:
   Unexpected subelement Confirmation
        at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
        at com.herongyang.www.service.RegistrationServiceStub.fromOM

Something is wrong here. Why I am getting "Unexpected subelement Confirmation" here? See next section for the explanation.

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