方式一:通過ClientProxyFactoryBean 調用
public static <T> T getService(String url, Class<T> cls) {
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(cls);
factory.setAddress(url);
T service = (T) factory.create();
return service;
}
方式二:通過JaxWsDynamicClientFactory 調用
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://192.168.1.102:12000/testService?wsdl");
Object[] objects = client.invoke("test", "test args");
附:cxf-dosgi發佈webservice時只需要增加以下配置:
Dictionary<String, String> props = new Hashtable<String, String>();
props.put("service.exported.interfaces","*");
props.put("service.exported.intents","SOAP");
props.put("service.exported.configs","org.apache.cxf.ws");
props.put("org.apache.cxf.ws.address","http://192.168.1.102:12000/testService?wsdl");