O'Reilly logo

Java and SOAP by Robert Englander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.4. Returning Custom Types

It's equally useful (and equally common) to return custom types from service method calls. We can enhance our trading service by offering a method that takes a single stock symbol as a parameter and returns its high and low trading prices for the day. The classes HighLow_ServerSide and HighLow_ClientSide represent the high/low prices on the server and client, respectively.

package javasoap.book.ch5;
public class HighLow_ServerSide {
   public float _high;
   public float _low;
   public HighLow_ServerSide(  ) {
   }
   public HighLow_ServerSide (float high, float low) {
      setHigh(high);
      setLow(low);
   }
   public float getHigh(  ) {
      return _high;
   }
   public void setHigh(float high) {
      _high = high;
   }
   public float getLow(  ) {
      return _low;
   }
   public void setLow(float low) {
      _low = low;
   }
}
  
package javasoap.book.ch5;
public class HighLow_ClientSide {
   public float _high;
   public float _low;
   public String toString(  ) {
      return "High: " + _high +
        " Low: " + _low;
   }
   public HighLow_ClientSide(  ) {
   }
   public float getHigh(  ) {
      return _high;
   }
   public void setHigh(float high) {
      _high = high;
   }
   public float getLow(  ) {
      return _low;
   }
   public void setLow(float low) {
      _low = low;
   }
}

The server-side class includes a parameterized constructor as a convenience for creating the return value; the client-side class includes a toString( ) method to make it easy for our client application to display the contents of the object after it's returned from the server. Let's add a new method to the BasicTradingService ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required