Eclipse版本 Eclipse IDE for Enterprise Java Developers 4.16
当然,使用eclipse低一点的版本也没有关系,但是需要是eclipse jee版本
本文通过已有的wsdl文件生成webService客户端 是开发 webService 客户端 最简单的办法
wsdl 地址我们使用上一篇文章开发好的服务地址,或者直接把wsdl 文件的本地路径填入service definition输入框也可以(例如 E:\Workspaces\Eclipse\businessWebService\WebContent\wsdl\Business.wsdl)
具体步骤看下文
创建一个java project
填写工程名称,然后finish
选择刚刚新建的项目 右键 new一个web service client 然后next
填入 wsdl文件地址
我填了上一篇文章生成的地址
http://localhost:8080/businessWebService/services/Business?wsdl
然后finish
即可生成客户端代码
然后我们写一个 带有main方法的测试类
package com.main;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.gg.BusinessServiceLocator;
public class Test {
public static void main(String[] args) throws RemoteException, ServiceException {
BusinessServiceLocator businessServiceLocator=new BusinessServiceLocator();
String retString=businessServiceLocator.getBusiness().sayHello("world");
System.out.println(retString);
}
}
然后运行
控制台输出
hello world
成功