xfire 1.2 实现webservice完整流程
1.打开 myeclipse 60 点击 file -->new -->web service project
Project name 为 xfirewebservice --》 finash
2.src目录下创建 包和相应的 java文件 如下所示:MathService.java
/**
*
*/
package com.test.ws;
/**
* @author Administrator
*implements IMath
*/
public class MathService {
public long add(int p1, int p2) {
return p1 + p2;
}
public long minus(int p3, int p4) {
// TODO Auto-generated method stub
return p3 -p4;
}
}
3. 修改 WebServices 文件夹下的 services.xml文件 ,内容如下:
服务名称MathService url :http://localhost:8080/WebserviceTest/MathService
完成服务的 类 <serviceclass>com.test.ws.MathService</serviceclass>
将 WebserviceTest 替换为自己的 项目名称
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://xfire.codehaus.org/config/1.0"><service><name>MathService</name><namespace>
http://localhost:8080/WebserviceTest/MathService
</namespace><serviceclass>com.test.ws.MathService</serviceclass></service></beans>
4. 部署 webservice
在浏览器 输入 http://localhost:8080/WebserviceTest/services/
出现如下提示 :
Available Services:
MathService [wsdl]
Generated by XFire ( http://xfire.codehaus.org )
表示 服务 启动成功, 至此 服务部署完成
测试 服务 :
项目中 需要引入 commons-httpclient-3.0.1.jar包 拷贝至 webroot下的 web-inf目录下的 lib目录中 即可
1. 编写 接口文件
package com.webservice.client;
public interface IMath {
long add(int p1,int p2);
long minus(int p3,int p4 );
}
2. 编写调用 文件
/**
*
*/
package com.webservice.client;
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;
/**
* @author Administrator
*
*/
public class Client {
public static void main(String[] args) {
// TODO 自动生成方法存根
Service srvcModel = new ObjectServiceFactory().create(IMath.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String helloWorldURL = "http://localhost:8080/WebserviceTest/services/MathService";
try {
//接口文件 说明有 哪些函数 可以用, helloWorldURL 提示 服务在哪里
IMath srvc = (IMath) factory.create(srvcModel, helloWorldURL);
// srvc.add(124, 456);
System.out.println("调用函数 add得到结果 :" + srvc.add(1516, 1515));
System.out.println("调用函数 minus得到结果 :" + srvc.minus(1516, 1515));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
测试结果如下 :
调用函数 add得到结果 :3031
调用函数 minus得到结果 :1
分享到:
相关推荐
webservice中用到的jar,xfire-jsr181-api-1.0-M1.jar,xfire-jsr181-api-1.0-M1.jar
spring+xfire( 编写webservice完整配置+案例)
Xfire在Spring下实现安全的WebService详述---配置 -
xfire-1.2.6.rar xfire-1.2.6.rar xfire-1.2.6.rar
xfire实现webservice实例,XFire WebService开发快速起步
xfire-1.2.6所有资源--实例 xfire-1.2.6所有资源--实例 xfire-1.2.6所有资源--实例
xfire-jsr181-api-1.0-实例化webservic
使用eclipse导入项目,既可使用。 【webservice----xfire 快速入门代码实训】----<下载不扣分,回帖加1分,欢迎下载,童叟无欺>
本文详细介绍了利用xfire组件实现webservice的服务端和客户端实例,适合入门参考和使用!
xfire框架构建webservice应用: (通过myeclipse自动生成代码,自动导入xfire jar包,需要用jdk5.0) 需要的jar包:xFire 1.2 Core Libraries/xFire 1.2 HTTP Client Libraries/xFire 1.2 JAXB2 Libraries
NULL 博文链接:https://smallbee.iteye.com/blog/1048468
xfire-jsr181-api-1.0-M1.jar xfire-jsr181-api-1.0-M1.jar
XFire--Webservice入门xfire
Spring+xFire实现webService
NULL 博文链接:https://zhangzhaoaaa.iteye.com/blog/1718819
NULL 博文链接:https://15838341661-139-com.iteye.com/blog/1139930
webService-xfire入门 webService-xfire入门
spring3.0整合Xfire1.2.6 开发webservice需要的jar包
用XFire1.2开发的java版webservice完整源码。由于jar包太大资源上传不了没有打包在内。相信大家可以自己导入包。
xfire的一个完整实例,不过我建议大家,学习完理论知识后,根据自己学得知识,手动练习一下,遇到异常就百度,一下,这样比较好!