在尝试了多种webservice客户端调用方法之后,还是觉得这种方法靠谱点儿,此方法用到了Apache的CXF框架,工具类源码如下: importjava.lang.reflect.Method;importorg.apache.cxf.jaxws.JaxWsProxyFactoryBean
在尝试了多种webservice客户端调用方法之后,还是觉得这种方法靠谱点儿,此方法用到了Apache的CXF框架,工具类源码如下:
import java.lang.reflect.Method; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; public class WsReq{ private String wsUrl; private Class<?> interfaceClz; pulbic WsReq(String wsUrl, Class<?> interfaceClz) { this.wsUrl = wsUrl; this.interfaceClz = interfaceClz; } public String invoke(String methodName, Object... params) throws Exception { Object obj = getWsObject(); Class<?>[] argsTypes = new Classs[params.length]; for (int i = 0; i < params.length; i ++) { if (params[i] != null) { argsTypes[i] = params[i].getClass(); } } Method method = interfaceClz.getMethod(methodName, argsType); String result = (String)method.invoke(obj, params); return result; } private Object getWsObject() { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setAddress(wsUrl); factory.setServiceClass(interfaceClz); Object obj = (Object)factory.create(); return obj; } }