第一步:wsdl2Java.bat文件编写
Axis_Lib表示依赖的jar包路径
Output_Path表示生成的class路径
Package包名 还需要手动更改
-p %Package%表示webservice服务端名称 (注:http://localhost/CHIMSWEB/services/ChimsAppImplService?wsdl)
set Axis_Lib="E:WorkspacesMyEclipse ProfessionalCHIMS_20151008WebRootWEB-INFlib" set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib% set Output_Path="E:WorkspacesMyEclipse ProfessionalCHIMS_20151008srccomzhongzhichimsserviceAppclient" set Package=com.zhongzhi.chims.service.App.client %Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o %Output_Path% -p %Package% http://localhost/CHIMSWEB/services/ChimsAppImplService?wsdl pause;
第二步:引入依赖jar包
第三步:运行wsdl2Java.bat批处理文件就可以生成代码,调用webservice了
package com.zhongzhi.chims.service.zhongkang; import java.io.StringReader; import java.net.URL; import java.util.Iterator; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; import org.dom4j.Document; import org.dom4j.DocumentHelper; import com.zhongzhi.chims.service.zhongkang.Client.BeinuoInterface; import com.zhongzhi.chims.service.zhongkang.Client.BeinuoServerService; import com.zhongzhi.chims.service.zhongkang.Client.BeinuoServerServiceLocator; import com.zhongzhi.common.func.BlankUtil; public class TestTcfWebService { public static void main(String[] args) { BeinuoServerService service=null; BeinuoInterface server=null; System.out.println("connect....");
//服务端地址 String strPortAddress = "http://localhost//services/reportServer"; URL portAddress; try { portAddress = new URL(strPortAddress); // 得到客户端服务. service = new BeinuoServerServiceLocator(); // 得到客户端stub. server = service.getBeinuoServerPort(portAddress); // 测试服务方法. String resultStr = server.getTCHFinfo("310101197001044432","001011","张健","123456"); } catch (Exception e) { e.printStackTrace(); } } }