java(jeecg框架) 调用CXF WebService接口的两种方式
2.靜態調用
// 創建WebService客戶端代理工廠JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();// 判斷是否拋出異常factory.getOutInterceptors().add(new LoggingInInterceptor());// 注冊webservice接口factory.setServiceClass(DeductionService.class);// 配置webservice地址factory.setAddress("http://localhost:7002/card/services/HelloWorld?wsdl");// 獲得接口對象CxfService service = (CxfService) factory.create();// 調用接口方法String result = service.sayHello("aaaaaaaaaa");System.out.println("調用結果:" + result);// 關閉接口連接System.exit(0);3.動態調用:
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
org.apache.cxf.endpoint.Client client = dcf
.createClient(“http://192.168.1.100:8080/QuestionnaireSurvey/cxf//questionWService?wsdl”);
// url為調用webService的wsdl地址
QName name = new QName(“http://icase.service.ynuyl.sx.com/”, “getData”);
// namespace是命名空間,methodName是方法名
String xmlStr = “”;
// paramvalue為參數值
Object[] objects;
try {
objects = client.invoke(name, xmlStr);
System.out.println(objects[0].toString());
} catch (Exception e) {
e.printStackTrace();
}
區別:靜態調用需要依賴service類,因為客戶端調用cxf webservice接口的過程中需要服務器端提供service,很不方便,如果同一個項目中則沒有區別。
動態調用完全不依賴service類,服務器端只要提供接口名和路徑就可以方便的調用。總結
以上是生活随笔為你收集整理的java(jeecg框架) 调用CXF WebService接口的两种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pt电阻测温c语言算法,铂电阻测温仪的设
- 下一篇: 计算机视觉行业,这_体育行业中计算机视觉