cxf 調用webservice的方式

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

發佈了30 篇原創文章 · 獲贊 20 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章