February 20, 2019
Hot Topics:

Building Web Services that Produce Multiple Return Values

  • March 2, 2005
  • By Jeyarani Venkatasamy and Nandhini Arumugam
  • Send Email »
  • More Articles »

Writing the service

The ExamResultService class contains a method called getResult() that returns multiple values. This may be confusing because the signature of getResult() method shows the return type as String. But here, returning multiple values is achieved by passing a parameter that acts as an input as well as output parameter. Such a parameter is called a IN-OUT parameter.

The getResult() method takes two parameters. The first parameter is a String called rollnumber, which is an input parameter; the second is of type StudentHolder, which we created in the previous step. Here, StudentHolder is an IN-OUT parameter. This StudentHolder object will get updated according to the rollnumber input. After invocation, the StudentHolder instance will contain updated values.

import onlineResult.Student;
import onlineResult.holders.*;
public class ExamResultService
   String result;
   Student student;
   public String getResult(String rollnumber,
                           StudentHolder studentHolder)
         result = new String("Pass");
         student = new Student("Albert","S","MCA");
         studentHolder.value = student;

      else if(rollnumber.equals("1001"))
         result = new String("Fail");
         student = new Student("Robert","F","MSc");
         studentHolder.value = student;

      else if(rollnumber.equals("1002"))
         result = new String("Pass");
         student = new Student("Mary","A","BSc");
         studentHolder.value = student;

         result = new String("No Match Found");
         student = new Student();
         studentHolder.value = student;

      return result;



Compile ExamResultService, StudentHolder, and Student into their corresponding directories. Use the following command to create the EAR file. Before you run the command, make sure that the classpath contains the service-related classes, Weblogic.jar, and webservices.jar provided by Weblogic.

>java  weblogic.webservice.servicegen
-destEar c:\Complex_inout_Student\ExamResultService.ear
-warName ExamResultService.war
-javaClassComponents ExamResultService
-serviceName ExamResultService
-serviceURI /ExamResultService
-targetNamespace http://www.mes.hp.com

Running the above command will create an ExamResultService.ear file. Now, you need to deploy this EAR file into the Weblogic server. Start Weblogic server and run the following command to deploy the war in Weblogic.

>java  weblogic.Deployer
-adminurl http://localhost:7001
-user admin
-password admin
-name ExamResultService
-source c:\Complex_inout_Student\ExamResultService.ear
-targets myserver
Note: You need to change the values according to your service before running this command.

Now, the service is deployed successfully. You can access your service with the URL http://localhost:7001/ExamResultService/ExamResultService.

Writing the Client

The clientgen ant task can be used to generate stubs for the deployed service. Here is build.xml.

<project name="buildWebservice" default="generate-client">
   <target name="generate-client">
<clientgen wsdl="http://localhost:7001/ExamResultService/

Running this task will generate an ExamResultService.jar file. You need to write a client using the stubs that have been generated and packed inside this JAR file. A sample client for accessing your Online Exam Results is given below. The generated JAR file needs to be set in the Classpath before compiling this client.

import examservice.*;
import javax.xml.rpc.holders.*;
import onlineResult.Student;
import onlineResult.holders.StudentHolder;

public class MyClient
   public static void main(String arg[])
      ExamResultServicePort myexam = new
      StudentHolder studentHolder = new StudentHolder();
      String res = myexam.getResult("1000",studentHolder);
      System.out.println("Result : "+res  );
      Student s = studentHolder.value;
      System.out.println("Name : "+s.getName()+
                         "\nGrade : "+s.getGrade()+"\nCourse :
      catch(Exception e)
         System.out.println("Exception "+e);

Running the sample client will give the following output:

>java MyClient
Result : Pass
Name : Albert
Grade : S
Course : MCA


We hope that this article helps you develop more useful Web services than before.

About the Authors

Nandhini Arumugam holds a Masters degree in Computer Applications from PSG College of Technology, Coimbatore. She has been working as a Software Engineer in the Telecom and Mobile Solutions Lab, Hewlett-Packard, Bangalore for more than one year. The domain of her experience includes Web services and J2EE-related technologies. She can be reached at nandhini.arumugam@hp.com.

Jeyarani Venkatasamy holds a Masters degree in Computer Applications from Sri Sarada College for Women, Tirunelveli. She has been working as a Senior Sofware Engineer in the Telecom and Mobile Solutions Lab, Hewlett-Packard, Bangalore for more than one year. The domain of her experience includes Web services, Java and J2EE-related technologies. She can be reached at jeyarani.venkatasamy@hp.com.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date