1.首先建立一个Web services EndPoint:
package Hello;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;
@WebService
public class Hello {
@WebMethod
public String hello(String name) {
return "Hello, " + name + "\n";
}
public static void main(String[] args) {
// create and publish an endpoint
Hello hello = new Hello();
Endpoint endpoint = Endpoint.publish("http://localhost:8080/hello", hello);
}
}
2.编译java Hello.Hello,并运行,然后将浏览器指向http://localhost:8080/hello?wsdl就会出现下列显示
Web Services
No JAX-WS context information available.
3.使用wsimport 生成客户端
使用如下:wsimport -keep -p webService.client http://localhost:8080/hello?wsdl
这时,会在当前目录中生成如下文件:
见附件中001.png,002.png
5.客户端程序:
class HelloClient{
public static void main(String args[]) {
HelloService service = new HelloService();
Hello helloProxy = service.getHelloPort();
String hello = helloProxy.hello("你好");
System.out.println(hello);
}
}