sendReceive() Method - Invoking a Named Operation

This section provides a tutorial example on how to use the sendReceive() method to invoke an operation defined in the service inside the ServiceClient object.

After the ServiceClient object created correctly to represent a service defined in a WSDL document, the next step is to invoke an operation defined in the service.

One way to invoke an operation is to call the sendReceive() method, which invokes a named operation that uses an In-Out MEP (Message Exchange Pattern) using this syntax:

   response = client.sendReceive(operationQName, request)
// "operationQName" specifies an operation within the service
//    using a new QName(tns,operationName)
//    "tns" specifies the target namespace of the Web service
// "request" specifies the SOAP Body element in the request message
//    as an object
// "response" receives the SOAP Body element in the response message
//    as an object

For other RPCServiceClient methods, see Axis documentation.

Here is my first test program for the sendReceive() method,

 * Copyright (c) 2009 All Rights Reserved.
import javax.xml.namespace.QName;
import org.apache.axis2.client.ServiceClient;
class Axis2ServiceClientSendReceive {
   public static void main(String[] args) {
      PrintStream out = System.out;

// Setting initial values
      String server = "";
      String wsdl = server+"Hello_WSDL_11_SOAP.wsdl";
      String tns = "";
      String serviceName = "helloService";
      String portName = "helloPort";

      try {
         ServiceClient client = new ServiceClient(null,
            new URL(wsdl), new QName(tns, serviceName), portName);
         OMElement request = null;
   OMElement response = client.sendReceive(
      new QName(tns, "Hello"), request);
      } catch (Exception e) {

Execution of this program is described below:

herong> java -cp .;\local\axis2\lib\* Axis2ServiceClientSendReceive

<hy:HelloResponse xmlns:hy="">
      Hello from server -

Note that I got the following error when running the same program with Axis2 1.4.1:

herong> java -cp .;\local\axis2\lib\* Axis2ServiceClientSendReceive

org.apache.axis2.AxisFault: Transport error:
   411 Error: Length Required
   at org.apache.axis2.transport.http.HTTPSender.handleResponse
   at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPS...
   at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.j...
   at org.apache.axis2.transport.http.CommonsHTTPTransportSender.w...
   at org.apache.axis2.transport.http.CommonsHTTPTransportSender.i...
   at org.apache.axis2.engine.AxisEngine.send(
   at org.apache.axis2.description.OutInAxisOperationClient.send(O...
   at org.apache.axis2.description.OutInAxisOperationClient.execut...
   at org.apache.axis2.client.OperationClient.execute(OperationCli...
   at org.apache.axis2.client.ServiceClient.sendReceive(ServiceCli...
   at Axis2ServiceClientSendReceive.main(Axis2ServiceClientSendRec...

Looks like this error has been fixed now in Axis2 1.7.8.

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

 Using WSDL Document in Java Apache Axis2/Java for WSDL

 Apache Woden for WSDL Documents in Java

 SoapUI - Web Service Testing Tool

 PHP SOAP Extension for WSDL

 Perl SOAP::Lite for WSDL

 Introduction to WSDL 1.1

 WSDL 1.1 Document Structure and Syntax

 WSDL 1.1 Binding Extension for SOAP 1.1

 SoapUI as WSDL 1.1 Testing Tool

 WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles

 PHP SOAP Extension for WSDL 1.1

 Perl SOAP::Lite for WSDL 1.1

Apache Axis2/Java for WSDL 1.1

 Creating Service Client with WSDL 1.1 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

 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

 Python SOAP Client: Zeep

 WSDL Related Terminologies

 Archived Tutorials


 Full Version in PDF/EPUB