1、易出现问题的地方,Jar包缺少或冲突
XFire使得在JavaEE应用中发布Web服务变得轻而易举。和其他Web服务引擎相比,
XFire的配置非常简单,可以非常容易地和Spring集成。
下载地址:http://xfire.codehaus.org/Download 但是jar很容易出错,我试了很久才成功网上虽然很多实例但是照着做也不容易成功主要是jar导致的失败让人很有挫败感,所以在此总结贴出比较多的Jar(有些jar未用到,但是建议保留)。
2、开发项目目录及Jars
3、创建webservice借口
package com.boonya.xfire.ws; public interface IUserServices { public String sayHello(String message); }4、 实现 webservice接口
package com.boonya.xfire.ws; public class UserServicesImpl implements IUserServices { public String sayHello(String message) { System.out.println(message); return message; } }5、 编写 代理 客户端 测试 类
package com.boonya.xfire.ws; import java.net.MalformedURLException; import org.codehaus.xfire.XFireFactory; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; public class UserTestClient { public static void main(String[] args) throws MalformedURLException { Service service = new ObjectServiceFactory() .create(IUserServices.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory .newInstance().getXFire()); String url = "http://localhost:8080/myws/services/UserServices"; IUserServices userService = (IUserServices) factory.create( service,url); String res = userService.sayHello("Hello boonya,you singned sucess!"); System.out.println(res); } }6、 在 src 目录 下 创建meta-inf, 在 其 下面 创建 xfire 文件夹, 并在 xfire 文件夹 下 创建 services. xml 文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>UserServices</name> <namespace>http://ws.com</namespace> <serviceClass>com.boonya.xfire.ws.IUserServices</serviceClass> <implementationClass>com.boonya.xfire.ws.UserServicesImpl</implementationClass> <style>wrapped</style> <use>literal</use> <scope>application</scope> </service> </beans>7、 配置 xfire 的 web.xml 文件
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <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> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>8、 将 myw s 加入 Tomcat 容器, 部署 并 启动
在浏览器输入如下内容访问
客户端后台代理测试结果如下:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。