Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top