1.创建 web service project 项目 service服务端
package com.hyan.service;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
//必须加入该注解
@WebService
public class ServiceHello {
/**
* @param args
*/
public String getValue(String key){
return key+" success";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//终端发布
Endpoint.publish("http://localhost:8888/service/ServiceHello", new ServiceHello());
System.out.println("ws publish success");
}
}
2.使用 wsimport 编译 wsdl 到client 项目
wsimport -s 编译到的目录
-p 编译到的包
-keep ws的 url或文件
3.调用
package com.ws.client.test;
import com.ws.client.ServiceHello;
import com.ws.client.ServiceHelloService;
public class TestWs {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ServiceHello sh = new ServiceHelloService().getServiceHelloPort();
String value = sh.getValue("123");
System.out.println("from ws value"+value);
}
}