1

How to create simple web service that can be used by Mobile application (Android/iPhone Apps) using java.

Please suggest the solution.

user1592586
  • 19
  • 1
  • 2

1 Answers1

6

The most simple web service in Java would be basically any class annotated with @Webservice and published via the Endpoint class.

As an example, an implementation that echo's a String:

@WebService
public class EchoService {

    public String echoHello(String name) {
        return "Hello " + name;
    }

}

You can publish that on localhost via:

EchoService service = new EchoService();    
Endpoint.publish("http://localhost:2000/echo", service);

This will publish a SOAP endpoint with document/literal binding. For more information, see the JAX-WS tutorial.

joergl
  • 2,850
  • 4
  • 36
  • 42