Creating Service Client with WSDL Document

This section provides a tutorial example on how to create a ServiceClient object with a given WSDL document, a service name and a port name defined in the WSDL document.

Before looking at other Axis2 class, let's take a closer look at how to create a service client object from an existing WSDL document using this constructor method:

   org.apache.axis2.client.ServiceClient client = 
      new ServiceClient(null, wsdlURL, serviceQName, portName)
// "null" indicates a default ConfigurationContext object to be used
// "wsdlURL" specifies a WSDL document using a new URL(wsdlUrlString)
// "serviceQName" specifies a service within the WSDL document
//    using a new QName(tns,serviceName)
//    "tns" specifies the target namespace of the Web service
// "portName" specifies a port within the service using the port name

Now let's write a test program,, to create a service client with my hello WSDL document, which is located at

 * Copyright (c) 2009 by Dr. Herong Yang,
 * All rights reserved
import javax.xml.namespace.QName;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
class Axis2ServiceClientHello {
   public static void main(String[] args) {
      PrintStream out = System.out;

// Setting initial values
      ConfigurationContext config = null;
      String wsdl = "file:///C:/herong/Hello_WSDL_11_SOAP.wsdl";
      String tns = "";
      String serviceName = "helloService";
      String portName = "helloPort";

      try {

// Creating a dynamic service client with a given WSDL
         ServiceClient client = new ServiceClient(
            new URL(wsdl), 
            new QName(tns, serviceName), 

// Printing ServiceClient object information
         out.println("ServiceClient object information:");
         out.println("   client: "+client);
         out.println("   client.getAxisConfiguration(): "
         out.println("   client.getAxisService(): "
         out.println("   client.getOptions(): "
         out.println("   client.getServiceContext(): "
         out.println("   client.getTargetEPR(): "

      } catch (Exception e) {

Compilation and execution of this program are described below:

C:\herong>\local\jdk\bin\javac -Djava.ext.dirs=\local\axis2\lib\

C:\herong>\local\jdk\bin\java -Djava.ext.dirs=\local\axis2\lib\
log4j:WARN No appenders could be found for logger 
log4j:WARN Please initialize the log4j system properly.

ServiceClient object information:
   client: org.apache.axis2.client.ServiceClient@1
   client.getAxisService(): helloService
   client.getOptions(): org.apache.axis2.client.Options@e80842
   client.getTargetEPR(): null

Notes on the test program code and output:

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

 What Is Axis2?

 Downloading and Installing Axis2/Java 1.4.1

 org.apache.axis2.client.ServiceClient Class

Creating Service Client with WSDL Document

 org.apache.axis2.client.Options - Operation Client Options

 sendReceive() Method - Invoking a Named Operation

 Turning Off the Chunked HTTP Flag

 AXIOM (AXIs Object Model) - document/literal Style - document/literal Style

 org.apache.axis2.rpc.client.RPCServiceClient Class - rpc/encoded Style - Socket Server Testing Program

 Capturing the HTTP Request from an Axis2 Client Program

 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

 SOAP 1.2 Binding - PHP, Java and Perl Clients

 WSDL Related Terminologies


 PDF Printing Version