方式一:通过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");