開發:隨筆記錄之 CXF 動態呼叫Webservice

執筆記憶的空白發表於2014-04-25

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;
}

}

本文允許轉載,但必須標明原文出處和作者.  如果覺得有用,請回復一下


相關文章