webService之创建客户端
二。创建客户端
(1)导出服务器端的接口jar文件.即将之前创建的服务器端的接口文件导出为jar包形式,然后引入到创建的客户端测试工程当中。(注意:导出接口文件层级深了也不行,我是直接到接口类右键导出jar文件,然后就可以引入到客户端测试工程当中了)
(2)引入XFire的jar包. (我引入了8个包)
(3)将集合中存储的对象类创建起来,即对应你存数据的javaBean
(4)创建servlet调用服务.
Service serviceModel = new ObjectServiceFactory().create(接口名.class); XFire xfire = XFireFactory.newInstance().getXFire(); XFireProxyFactory factory = new XFireProxyFactory(xfire); String serviceUrl = "服务地址"; // "http://localhost:8080/res2/services/allresfood"; 注意:此处后边不需要“?wsdl” ResfoodWebService client = null; try { client = (ResfoodWebService) factory.create(serviceModel, serviceUrl); } catch (Exception e) { System.out.println("Client call webservice has exception: " + e.toString()); } List<Resfood> list = client.findByPage(); for( Resfood rf: list){ System.out.println(rf); }