Web Service简介
Web Service是应用程序组件,使用开放协议进行通信。
最重要的事情是协同工作。可以在不同的应用程序与平台之间交换数据。
Web Service平台元素
- SOAP (简易对象访问协议)
- UDDI (通用描述、发现及整合)
- WSDL (Web services 描述语言)
最简单的Web Service
以Java为例,服务器端WS发布
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class SayHelloServer {
public String sayHello(String name) {
return "Hello,WS test" + name;
}
public static void main(String[] args) {
// 发布
Endpoint.publish("http://localhost:8081/hello", new SayHelloServer());
}
}
客户端调用
public class SayHelloClient {
public static void main(String[] args) {
SayHelloServer say = new SayHelloServer();
String result = say.sayHello("あいうえお");
System.out.println(result);
}
}