1、服务端代码:
package com.sxit; import java.util.ArrayList; import java.util.List; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public class GetList { @WebMethod public List<String> getList(){ List<String> list = new ArrayList<String>(); list.add("sb1"); list.add("sb2"); list.add("sb3"); return list; } }
2、生成wsdl文件:
E:\Workspaces\Service\WebRoot\WEB-INF>wsgen -cp E:\Workspaces\Service\WebRoot\WE B-INF\classes com.sxit.GetList -wsdl
3、根据wsd文件和binding.xml文件生成本地代码:
E:\Workspaces\Service\WebRoot\WEB-INF>wsimport -b binding.xml -s in GetListServi ce.wsdl
4、客户端代码(轮询):
package com.sxit; import java.util.List; import java.util.concurrent.ExecutionException; import javax.xml.ws.Response; public class SynchronizeClient { public static void main(String[] args) { GetListService service = new GetListService(); GetList port = service.getGetListPort(); Response<GetListResponse> response = port.getListAsync(); while(!response.isDone()){ System.out.println("未返回...."); } try { GetListResponse get = response.get(); List<String> list = get.getReturn(); for(String str:list){ System.out.println(str); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } }
5、打印信息:
未返回.... 未返回.... 未返回.... 未返回.... 未返回.... 未返回.... 未返回.... 未返回.... 未返回.... 未返回.... 未返回.... sb1 sb2 sb3