久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java使用xfire搭建webservice服務(wù)的過(guò)程詳解

瀏覽:5日期:2022-08-29 10:22:10

前言

以前用的都是 apache 的cxf來(lái)搞webservice,今天做項(xiàng)目發(fā)現(xiàn)這個(gè)項(xiàng)目用的是 xfire,于是搭一個(gè),寫(xiě)個(gè)demo用一下,在此記錄一下過(guò)程。

搭建過(guò)程

本文使用的是maven形式的web工程。不知道如何搭建web工程的看上一篇博文。

引入xfire的依賴(lài)

<dependency> <groupId>org.codehaus.xfire</groupId> <artifactId>xfire-all</artifactId> <version>1.2.6</version></dependency>

配置web.xml

<servlet> <servlet-name>XFireServlet</servlet-name> <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/xfire/services.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>

編寫(xiě)接口

public interface HelloService { public String helloService();}

編寫(xiě)實(shí)現(xiàn)類(lèi)

public class HelloServiceImpl implements HelloService { public String helloService() { return '1111'; }}

配置xfire的services的配置文件

該配置文件通過(guò)查看源碼,默認(rèn)在META-INF下的xfire的services.xml。我將目錄放在了resource下,去掉了META-INF。可通過(guò)上方的web.xml配置文件的地址。上方有例子。

<?xml version='1.0' encoding='UTF-8'?><beans> <service xmlns='http://xfire.codehaus.org/config/1.0'> <name>webService</name> <namespace>http://jichi.com/</namespace> <serviceClass>com.HelloService</serviceClass> <implementationClass>com.HelloServiceImpl</implementationClass> </service></beans>

編寫(xiě)一個(gè)訪問(wèn)webservice的方法

public static Object processWsMethod(String url,String methodName,Object ... params){Object result = null;try {if(!url.endsWith('?wsdl')){url += '?wsdl';}URL urls = new URL(url);Client client = new Client(urls);Object[] results = client.invoke(methodName,params);if(results!=null){if(results.length==1)result = results[0];elseresult = results;}} catch (Exception e) {e.printStackTrace();}return result;}

編寫(xiě)測(cè)試方法

@Test public void testMyWebService(){ String aa = (String) WebServiceUtil.processWsMethod('http://localhost:8080/services/webService', 'helloService'); System.out.println(aa); }

結(jié)果

控制臺(tái)打印111.搭建成功。

到此這篇關(guān)于使用xfire搭建webservice服務(wù)的過(guò)程詳解的文章就介紹到這了,更多相關(guān)使用xfire搭建webservice服務(wù)內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 区。| 根河市| 镇原县| 铁岭市| 福泉市| 滁州市| 徐闻县| 丁青县| 静宁县| 页游| 隆化县| 天全县| 遂溪县| 城市| 神农架林区| 武山县| 奇台县| 酒泉市| 东源县| 赞皇县| 红河县| 会昌县| 留坝县| 邓州市| 镇安县| 图木舒克市| 中卫市| 台东县| 苏尼特右旗| 武功县| 育儿| 江永县| 揭西县| 兴安县| 孝感市| 田阳县| 土默特右旗| 仁寿县| 济南市| 漠河县| 明星|