webservice
发布时间:2020-12-16 23:22:20 所属栏目:安全 来源:网络整理
导读:1.//不用通过wsdl生成类来调用ws,采用发送soap包的方式,动态调用,很方便? 2.import org.apache.cxf.endpoint.Client;???? 3.import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;???? 4.import org.springframework.context.support
1.//不用通过wsdl生成类来调用ws,采用发送soap包的方式,动态调用,很方便? 2.import org.apache.cxf.endpoint.Client;???? 3.import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;???? 4.import org.springframework.context.support.ClassPathXmlApplicationContext;???? 5.public class TestMain {???? 6.? 7. public static void main(String[] args) {???? 8.?? String xmlInput = "<?xml version="1.0" encoding="UTF-8"?><request><operateType>query????????????? </operateType><dbType>sqlserver</dbType><orderBy></orderBy><userId>1</userId>????????????? <start>0</start><limit>20</limit><processName></processName></request>";?????? 9.? JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();???? 10.? String wsUrl = "地址"??? 11.? String method = "findAllUser";? 12.? Client client = dcf.createClient(wsUrl);???? 13.? Object[] res = null;???? 14.? try {???? 15.?? res = client.invoke(method,xmlInput);? 16.? } catch (Exception e) {???? 17.?? e.printStackTrace();???? 18.? }???? 19.??? System.exit(0);???? 20. }???? 21.}? 2,生成客户端代码方式? 这种适用cxf wsimport -keep -d D:/? -p ok http://127.0.0.1/Service.asmx?WSDL import java.util.List; import ok.ServiceSoap; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import com.ces.xarch.core.web.struts2.StringIDDefineServiceDaoController; import com.ces.zwww.dao.MacRoomDao; import com.ces.zwww.entity.MacRoom; import com.ces.zwww.service.MacRoomService; public static? List<MacRoom> saveMac(){ ? //http://127.0.0.1/Service.asmx ? String xml ; ? try { ? JaxWsProxyFactoryBean factory1 = new JaxWsProxyFactoryBean(); ? factory1.setServiceClass(ServiceSoap.class);? ? factory1.setAddress("http://127.0.0.1/Service.asmx?wsdl");? ? ServiceSoap u = (ServiceSoap) factory1.create();? ? xml= u.getAllMachineRooms(); ? System.out.println(xml); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } ? // return? this.getService().saveMac(xml); return? null; ? } 用Eclipse生成的如果不是cxf类型是anxi是调用不了的,要用anxi调用
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Bash:递归地将子目录添加到路径
- Angular 7上的虚拟滚动 – 默认情况下高度为零
- windows – 等待标题时,Docker Toolbox Tutorial Client.T
- redis学习--的持久化数据备份(RDB和AOF)
- ng-conf-2017 - Angular Form Validation
- 显示vim中的尾随空格
- 在ETL工具Spoon中调用WebService的方法
- 解决docker pull镜像速度慢的问题的方法
- twitter-bootstrap – 下拉菜单中的Twitter datepicker
- shell脚本学习总结----head+tail+chmod+chown+chattr+ln