1

如何使用 java 创建可供移动应用程序(Android/iPhone 应用程序)使用的简单 Web 服务。

请提出解决方案。

4

1 回答 1

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.

于 2012-08-13T10:18:03.413 回答