接上篇:使用Java SE 6 创建独立 Web Services - 服务端
注意:生成客户端时需要服务端运行(参考上篇),或提供wsdl文件
进入CMD:
运行: F:>wsimport -keep -s . -p com.client http://localhost:8888/wsServerExample?wsdl
会在F:下生成com/client目录 里面包括生成的客户端代码
package com.client;
import javax.xml.ws.BindingProvider;
public class SayHelloClient {
public static void main(String args[]) {
SayHelloService shs = new SayHelloService();
SayHello sh = (SayHello) shs.getSayHelloPort();
((BindingProvider)sh).getRequestContext().put(BindingProvider.
ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8888/wsServerExample");
System.out.println( ((BindingProvider)sh).toString() );
System.out.println(sh.getGreeting("Fiona"));
}
}