1.创建web service项目
2.配置web.xml
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
3.编写接口及实现类
4.配置service.xml
如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>ShowTimeService</name>
<serviceClass>com.web.IShowTimeService</serviceClass>
<implementationClass>
com.web.ShowTimeService
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
</beans>
5.布署tomcat, 运行tomcat
访问:http://localhost:8080/项目名称/services
点击超链接:wsdl
可以看到服务描述文件
测试,调用该服务
=================方法一
Client client = new Client(new URL("http://localhost:8080/showtime/services/ShowTimeService?wsdl"));
Object[] obj = client.invoke("getTime", new Object[]{});
System.out.println(obj[0]);
================方法二
//创建服务接口模板
//Service smodel = (Service) new ObjectServiceFactory().create(IShowTimeService.class);
////创建代理工厂
//XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
////定义WEB服务地址
//String url = "http://localhost:8080/showtime/services/ShowTimeService";
//// 根据接口模板和WEB服务地址返回服务类
//IShowTimeService s = (IShowTimeService)factory.create( smodel, url);
//String time = s.getTime();
//System.out.println(time);