似乎 jdk 6.0 已经带有一个 jax-ws 实现,以及一个可以嵌入的小服务器。我还没有弄清楚所有的部分,但这是一个开始:
mkdir -p helloservice/endpoint/
helloservice/endpoint/Hello.java :
package helloservice.endpoint;
import javax.jws.WebService;
@WebService()
public class Hello {
private String message = new String("Hello, ");
public void Hello() {}
public String sayHello(String name) {
return message + name + ".";
}
}
你好服务/端点/Server.java:
package helloservice.endpoint;
import javax.xml.ws.Endpoint;
public class Server {
protected Server() throws Exception {
System.out.println("Starting Server");
Object implementor = new Hello();
String address = "http://localhost:9000/SoapContext/SoapPort";
Endpoint.publish(address, implementor);
}
public static void main(String args[]) throws Exception {
new Server();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
}
构建事物:
mkdir build
javac -d build helloservice/endpoint/*java
$JAVA_HOME/wsgen -d build -s build -classpath . helloservice.endpoint.Hello
运行这个东西:
java -cp build helloservice.endpoint.Server
现在在http://localhost:9000/SoapContext/SoapPort上运行的东西。您可以在http://localhost:9000/SoapContext/SoapPort?WSDL上获取 wsdl
还没来得及做客户..