开发:随笔记录之 CXF 动态调用Webservice

2020-12-25 10:47:28 浏览数 (1)

import javax.xml.rpc.ServiceException; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import org.apache.log4j.Logger;

public class WebServiceUtil2 {

static Logger log = Logger.getLogger(WebServiceUtil2.class); public static Object invokeWebService2(String url, String method, Object obj) throws RemoteException, ServiceException { System.out.println("调用的地址:" url); //例:http://192.168.1.69:8001/cat/CatService?wsdl System.out.println("调用的方法:" method); //调用的webservice方法 System.out.println("传入的参数:" obj); //传入的参数 JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(); org.apache.cxf.endpoint.Client client = factory.createClient(url); Object[] result = null; try { if (null == obj) { result = client.invoke(method); } else { result = client.invoke(method, obj); } } catch (Exception e) { e.printStackTrace(); } return result; }

}

本文允许转载,但必须标明原文出处和作者. 如果觉得有用,请回复一下

0 人点赞