使用xfire搭建webservice服务
服务 搭建 webservice 使用
2023-09-27 14:21:58 时间
前言
以前用的都是 apache 的cxf来搞webservice,今天做项目发现这个项目用的是 xfire,于是搭一个,写个demo用一下,在此记录一下过程。
搭建过程
本文使用的是maven形式的web工程。不知道如何搭建web工程的看上一篇博文。
引入xfire的依赖
<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>
编写接口
public interface HelloService {
public String helloService();
}
编写实现类
public class HelloServiceImpl implements HelloService {
public String helloService() {
return "1111";
}
}
配置xfire的services的配置文件
该配置文件通过查看源码,默认在META-INF下的xfire的services.xml。我将目录放在了resource下,去掉了META-INF。可通过上方的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>
编写一个访问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];
else
result = results;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
编写测试方法
@Test
public void testMyWebService(){
String aa = (String) WebServiceUtil.processWsMethod("http://localhost:8080/services/webService", "helloService");
System.out.println(aa);
}
结果
控制台打印111.搭建成功。
相关文章
- Widnows本地搭建WebDav服务,并内网穿透公网可访问
- 利用Ngnix代理基于Baget搭建私有Nuget服务
- 使用docker搭建dns服务,解决内网机器用域名无法访问内网服务问题,并设置转发使除此之外的域名可正常解析
- Apache Traffic Server服务搭建
- 搭建web项目结合spring+cxf的webservice服务
- SpringCloud Hystrix使用和配置,SpringCloud Hystrix服务熔断降级
- 高擎信息安全大旗,打造“互联网+”新服务模式
- FastFDS----分布式文件服务系统服务端搭建
- Redis缓存服务搭建及实现数据读写
- 【HMS Core】运动健康服务如何查询应用已授权的权限列表
- 华为云从入门到实战 | 云服务概述与华为云搭建Web应用
- 引领新 ICT,华为以开放式媒体信息服务新平台加速数字变革
- 下一代时间同步服务 Chrony入门
- 微服务SpringBoot+Neo4j搭建企业级分布式应用拓扑图