通過http://localhost:7002/card/services/helloworld?wsdl訪問到xml如下,說明接口寫對了。
1.靜態調用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// 創建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 ); |
2.動態調用:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
jaxwsdynamicclientfactory dcf = jaxwsdynamicclientfactory.newinstance(); org.apache.cxf.endpoint.client client = dcf .createclient( "http://localhost:7002/card/services/helloworld?wsdl" ); // url為調用webservice的wsdl地址 qname name = new qname( "http://dao.xcf.digitalchina.com/" , "sayhello" ); // namespace是命名空間,methodname是方法名 string xmlstr = "aaaaaaaa" ; // 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類,服務器端只要提供接口名和路徑就可以方便的調用。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對服務器之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
原文鏈接:https://blog.csdn.net/qq_26562641/article/details/71534715