加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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调用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读