import javax.jws.WebService;
@WebService
public interface IMyService {
public void add(int a, int b);
}
import javax.jws.WebService;
@WebService(endpointInterface="test.service.IMyService")
public class MyServiceImpl implements IMyService{
public void add(int a, int b) {
System.out.println(a+b);
}
}
import javax.xml.ws.Endpoint;
public class TestMyService {
public static void main(String[] args) {
String address="http://localhost:8888/ns";
Endpoint.publish(address, new MyServiceImpl());//启动webservice
}
}
public class TestClient {
public static void main(String[] args) throws Exception {
String urlStr = "http://localhost:8888/ns?wsdl";
URL url = new URL(urlStr);
QName qname = new QName("http://service.test/","MyServiceImplService");
Service service = Service.create(url,qname);
IMyService s = service.getPort(IMyService.class);
s.add(1, 3);
}
}
创建另一个项目
bin下运行:
wsimport -d d:/01 -keep -verbose http://localhost:8888/ns?wsdl
-d 生成的路径
-keep 指定是否生成源文件(java后缀的文件)
-verbose 详细信息
后边的是webservice的地址
生成的文件拷贝到新项目
进行测试
public class TestClient2 {
public static void main(String[] args) {
MyServiceImplService service = new MyServiceImplService();
IMyService dd = service.getMyServiceImplPort();
dd.add(1, 2);
}
}