les2
les2

Reputation: 14479

can jax-ws web methods return objects that have static methods?

public class Pojo {
   private String value;

   public static void printValue() {
      System.out.println("value=" + value);
   }
}

I would want to return this from a web service as follows:

@WebService
public class MyService {
   @WebMethod
   public Pojo getPojo() {
      return new Pojo();
   }
}

Can't seem to find the definitive answer on whether I can, should, can't, or shouldn't.

Upvotes: 0

Views: 1260

Answers (2)

Vladimir Dyuzhev
Vladimir Dyuzhev

Reputation: 18336

Only data are sent over the wire. Static or non-static methods are not sent.

If on the receiving side you bind the data to the same class -- fine, you have your methods back, but SOAP has nothing to do with it, it's your own trickery. Clients written in other languages (C#, python, ...) won't have your method, of course.

P.S. The class of any object you're sending back always has methods. Your Pojo is implicitely subclassed from Object, and thus have toString(), hashCode(), and so on. JAX-WS doesn't care.

Upvotes: 2

matt b
matt b

Reputation: 139931

No. Think about it:

  1. Web services are meant to be platform-independent
  2. What is sent across the wire is simply XML (or some other format) data

So how would you be able to send across the wire a static method? How would non-Java clients be able to interpret your web service's response?

Upvotes: 1

Related Questions