转自:http://rargers.iteye.com/blog/195503
也可以参考:http://blog.sina.com.cn/s/blog_477252210100a7l4.html
首先下载xfire包,目前最新的是1.2.6,
下载地址:http://xfire.codehaus.org/Download
一.新建一个web工程,取名为xfire,到入xfire-all-1.2.6.jar和lib下面所需要的包。
二.
创建接口类:
- package com.zx.ws.test;
- public interface TestService {
- int add(int p1, int p2);
- }
创建接口的实现类:
import com.zx.ws.test.TestService;
class TestServiceImp implements TestService{
int add(int p2)
{
return p1 + p2;
}
三.在meta-inf下新建xfire文件夹,创建services.xml文件,配置如下:
- <beans xmlns="http://xfire.codehaus.org/config/1.0">
- servicespan style="color: #ff0000;">name>TestService</namespace>http://com/zx/ws/test/TestServicespanserviceClass>com.zx.ws.test.TestServiceimplementationClass>com.zx.ws.test.TestServiceImpbeans>
web.xml 配置如下:
<?xml version="1.0" encoding="UTF-8"?>
web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"display-name>webserviceservletservlet-name>XFireServletservlet-class org.codehaus.xfire.transport.http.XFireConfigurableServlet
servlet-mappingurl-pattern>/servlet/XFireServlet/*>/services/*web-app
启动tomcat,然后在浏览器中输入http://localhost:8080/xfire/services/,如果显示
Available Services:
- TestService [wsdl]<!----><!---->
或者输入http://localhost:8080/xfire/services/TestService?wsdl,如果正常显示wsdl文件的话就配置成功。
客户端测试:
首先把xfire工程的打成jar包
新建web动态工程,倒入xfire的包,和刚才的xfire工程的打包。
import java.net.MalformedURLException;
import java.rmi.remoteexception;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import com.zx.ws.test.TestServiceImp;
class MyClient {
static void main(String[] args) {
try
{
Service serviceModel = new ObjectServiceFactory() .create(TestService.class, "TestService", "http://com/zx/ws/test/TestService",85); font-weight:bold">null);
TestService service = (TestService) new XFireProxyFactory().create( serviceModel, "http://localhost:8080/xfire/services/TestService");
//使用 XFire 与 Spring 开发 Web Service 11
System.out.println("返回值是"+service.add(12,12));
}
catch (MalformedURLException e) {
e.printstacktrace();
}
}
然后运行,如果控制台输出:
返回值是24
则说明客户端成功。
ps:如果出现class path resource [meta-inf/xfire/services.xml] cannot be opened because it does not exist
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。