Web服务,XFire的一个例子
Web服务优点
互操作性:实现不同系统间的相互调用(语言无关、平台无关)
Web服务是什么
Web服务的体系结构
Web服务需要遵守的技术标准
2. SOAP(表示WEB服务信息交换的协议)
3. WSDL(WEB服务描述语言)
4. UDDI(统一描述发现和集成)
使用Web服务的一个例子
添加XFire用户库
客户端调用Web服务
训练要点:
掌握利用XFire创建客户端,调用Web服务
需求说明:
任意输入一个数字n,返回1+2+…+n的累加和, 并在控制台显示出来
实现思路:
1、创建服务接口SumService.java
2、创建客户端调用类Client.java
3、运行求数字累加和Web服务
4、运行客户端调用服务,传入参数,获得运行结果
创建Web Service Project
<servlet> <display-name>XFireServlet</display-name> <servlet-name>XFireServlet</servlet-name> <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>services.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>
新建接口和实现类:
新建接口:
cn.edu.hqu.service下SumService;
package cn.edu.hqu.service; public interface SumService { /** * 返回1-n的累加和 * @param n * @return */ public int getSum(int n); }
cn.edu.hqu.service.impl下SumServiceImpl:
package cn.edu.hqu.service.impl; import com.service.SumService; public class SumServiceImpl implements SumService { public int getSum(int n) { int sum = 0; for (int i = 1; i <= n; i++) { sum += i; } return sum; } }
在src下新建services.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>SumService</name> <serviceClass>cn.edu.hqu.service.SumService</serviceClass> <implementationClass>cn.edu.hqu.service.impl.SumServiceImpl</implementationClass> <style>wrapped</style> <use>literal</use> <scope>application</scope> </service> </beans>
部署到tomcat启动,访问localhost:8080/SumWebService/services
Web服务的调用
引入服务端那个项目SumWebService
右击项目,Properties
Client新建SumClinet类
public static void main(String[] args) throws Exception { //加载xfire //创建服务 Service service = new ObjectServiceFactory().create(SumService.class); //WSDL地址 String url = "http://localhost:8080/SumWebService/services/SumService"; XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire()); SumService sumService = (SumService) factory.create(service, url); //保证服务端有开启 System.out.println(sumService.getSum(100)); }
运行之前,webService服务端(SumWebService)要先部署启动;
运行main,控制台输出5050 ;
另外一种方式 SumClinet:
public static void main(String[] args) throws Exception { String wsdlLocation = "http://localhost:8080/SumWebService/services/SumService?wsdl"; Client client = new Client(new URL(wsdlLocation)); Object[] o =client.invoke("getSum",new Object[]{100}); System.out.println(o[0]); }
运行main输出结果;
下的org.codehaus.xfire.transport.http.XfireConfigurableServlet进到该类:
我们可以看到
private final static String CONFIG_FILE = "META-INF/xfire/services.xml";
默认路径是在META-INF/xfire/services.xml
源码里:
private String getConfigPath() { if (configPath == null || configPath.length() == 0) { return CONFIG_FILE; } return configPath; }
一开始会得到这个路径,如果路径为空的话,就会使用默认的路径;
所以我们在wen.xml里买指定 configPath路径,src下直接写文件名
<init-param> <param-name>config</param-name> <param-value>services.xml</param-value> </init-param>
这样就不会报错了,或者可以将services.xml放在新建的META-INF/xfire/services.xml下;
Xfire下载:http://pan.baidu.com/s/1ntx8yLF
代码:http://pan.baidu.com/s/1vmXtG
Web服务,XFire的一个例子的更多相关文章
- 【记录一个问题】铁威马NAS存储中的人人影视APP,其WEB服务占满一个CPU核
终端登录后,top命令发现rrshareweb这个进程把单个CPU核占满了. 发现其实是人人影视的web服务,而这个服务里面我还根本未使用. 卸载这个app后正常.
- 使用Spring进行远程访问与Web服务
1.1. 简介 Spring为各种远程访问技术的集成提供了整合类.Spring使得开发具有远程访问功能的服务变得相当容易,而这些远程访问服务由普通Spring POJO实现.目前,Spring支持 ...
- (转)Web Service入门简介(一个简单的WebService示例)
Web Service入门简介 一.Web Service简介 1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从I ...
- Web Service入门简介(一个简单的WebService示例)
Web Service入门简介 一.Web Service简介 1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从I ...
- Nginx Web服务(一)
一.Nginx原理介绍 1.1:什么是Nginx Nginx是一个开源的,支持高性能.高并发的WWW服务和代理服务软件 1.2:Nginx的功能特点及应用场合 ① 支持高并发:能支持几万并发连接,特别 ...
- J2EE基础之Web服务简介
J2EE基础之Web服务简介 1.什么是Web服务? 在人们的日常生活中,经常会查询网页上某城市的天气信息,这些信息都是动态的.实时的,它是专业的气象站提供的一种服务.例如,在网上购物时,通常采用网上 ...
- 【Java】Web 服务编程技巧与窍门: 在 UDDI 注册中心为 Web 服务注册开发 UDDI Java 应用程序
本技巧建立了一个使用统一描述.发现和集成 (Universal Description, Discovery, and Integration,UDDI) 来注册应用程序级消费的 Web 服务实例.作 ...
- IIS Web服务扩展中添加ASP.NET4.0
问题 服务器上安装了ASP.NET 4.0.30319组件,但是在IIS的Web服务扩展中并没有找到ASP.NET v4.0.30319这项,这导致基于.NET4.0开发的网页都无法正常浏览(404错 ...
- EJB_开发EJB容器模型的WEB服务
开发EJB容器模型的WEB服务 WEB服务 Web服务也是一种分布式技术,它与EJB最大的不同是,Web服务属于行业规范,可以跨平台及语言.而EJB属于Java平台的规范,尽管理论上可以跨平台,但实现 ...
随机推荐
- [HDU 3507]Print Article
Description Zero has an old printer that doesn't work well sometimes. As it is antique, he still lik ...
- [Luogu 3807]【模板】卢卡斯定理
Description 给定n,m,p(1≤n,m,p≤10^5) 求 C_{n+m}^{m} \mod p 保证P为prime C表示组合数. 一个测试点内包含多组数据. Input 第一行一 ...
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- 基于vfs实现自己的文件系统
1.Linux 文件系统组成结构 linux文件系统有两个重要的特点:一个是文件系统抽象出了一个通用文件表示层--虚拟文件系统或称做VFS.另外一个重要特点就是它的文件系统支持动态安装(或说挂载等), ...
- ●BZOJ 3622 已经没有什么好害怕的了
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3622 题解: 容斥,dp1).可以求出需要多少对"糖果>药片"(K ...
- UVA 3713 Astronauts
The Bandulu Space Agency (BSA) has plans for the following three space missions: • Mission A: Landin ...
- Linux查看Tomcat是否多次重启命令
1.查看命令 ps -ef|grep apache-tomcat-9090|grep -v grep|awk '{print $2}' 如果存在两个端口则多次重启, 2.停掉命令: kill -9 ...
- nginx负载均衡及详细配置
接上篇nginx配置,然后再准备两台web服务器: nginx服务器:192.168.0.241 web1:192.168.0.141 web2:192.168.0.142 一.两台web服务器先安装 ...
- 提高数据库的查询速率及其sql语句的优化问题
在一个千万级的数据库查寻中,如何提高查询效率? 1)数据库设计方面: a.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. b.应尽量避免在 ...
- A TensorBoard plugin for visualizing arbitrary tensors in a video as your network trains.Beholder是一个TensorBoard插件,用于在模型训练时查看视频帧。
Beholder is a TensorBoard plugin for viewing frames of a video while your model trains. It comes wit ...