dcsimg
August 20, 2017
Hot Topics:

Building Web Services that Produce Multiple Return Values

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

Web service operations typically return a single value. This may not be true in all cases. So, you need a way to return multiple values from a Web service operation. This article explains the procedure for creating, exposing, and invoking a Web service with multiple return values in detail.

The aim of this article is to explain ways to return multiple values from a Web service operation. There are two ways of doing this; they are:

  1. Return type can be a Complex Data type with muliple parts or arrays.
  2. Make use of In-Out Parameters in the Web service operations.

This article concentrates on the second option of implementing it, providing a step-by-step procedure for creating a Web service and a client to access it. This article assumes that the underlying Application Server is BEA Weblogic 8.x.

Creating a Web Service with Multiple Return Values

In Weblogic, Holders can be used to make Web service operations return multiple values.The return type can be primitive or User-defined. The JAX-RPC provides Holders for Primitive data types. They are available in the javax.xml.rpc.holders package. You need to provide Holders for Complex/User defined data types.

We have taken a simple example called "Online Exam Results" service that takes a roll number as input and returns the result of 'pass/fail' as a String. It also returns a complex object called Student that will give details about grade, course, and name of the student.

Here is the Student type class.

package onlineResult;

public class Student
{
   String name;
   String grade;
   String course;

   public Student()
   {}

   public Student(String name,String grade,String course)
   {
      this.name = name;
      this.grade = grade;
      this.course = course;
   }

   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }
   public String getGrade()
   {
      return grade;
   }

   public void setGrade(String grade)
   {
      this.grade = grade;
   }
   public String getCourse()
   {
      return course;
   }

   public void setCourse(String course)
   {
      this.course = course;
   }

}

Writing the holder

The Holder that you create should be a final class named in the format "DataType" + Holder; for example, 'StudentHolder'. StudentHolder needs to implement the javax.mxl.rpc.holders.Holder interface. The attribute defined in the class should be named 'value'. The StudentHolder class needs to provide two constructors: a default constructor and a full constructor. The Holder class should be placed in a directory called 'holders' under the directory where the User-defined data type class exists. In this example, the StudentHolder class is placed in the 'holders' directory, which is under the 'OnlineResult' directory, which contains the User-defined data type 'Student'.

package onlineResult.holders;

import onlineResult.Student;
import javax.xml.rpc.holders.Holder;

public final class StudentHolder implements Holder
{
   public Student value;
   public StudentHolder()
   {
      value = new Student();
   }

   public StudentHolder(Student value)
   {
      this.value = value;
   }
}




Page 1 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.

Sitemap | Contact Us

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