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平台的规范,尽管理论上可以跨平台,但实现 ...
随机推荐
- OpenGL新手框架
开始学习用OpenGL,也就想显示一些点,以为挺简单的,哎,看了两天才会画三维的点,做个总结. 使用OpenGL的基本流程 int main(int argv, char *argc[]) { //初 ...
- swift中editingStyleForRowAtIndexPath的写法
效果图: 首先要实现这句tableView.setEditing(true, animated: true)才能弹出左侧的小圆圈 然而在oc中tableview删除的写法百度一下很常见但是swift中 ...
- cocos2dx 3.x以上(Sprite精灵类的相关属性与创建)
// // MainScene.cpp // helloworld // // Created by apple on 16/9/19. // // #include "MainSce ...
- JS constructor
1.每个对象都有一个constructor,都指向创建该对象的方法. 2.function对象的prototype的constructor也是指向该方法.如果对prototype进行重写,constr ...
- Nginx优化—配置优化
完整配置如下所示: user nginx; #运行的用户 pid /var/run/nginx.pid; worker_processes auto; #定义了nginx对外提供web服务时的word ...
- python学习:字典
字典 1.查询内存地址 a = 10 print(id(a)) b = a print(id(b)) b = 15 print(id(b)) 2. 数据类型 不可变类型:整型.字符串.元组 可变类型: ...
- Linux基础入门-用户及文件权限管理
一.Linux用户管理: 不同的用户的文件都是放在同一个物理磁盘上的甚至同一个逻辑分区或者目录里,但是由于Linux的用户管理和权限机制,不同用户不能轻易查看.修改彼此的文件. 1. 查看用户: wh ...
- 动态规划-LCS最长公共子序列
#include<iostream> #include<cstdio> #include<cstring> #include<string> using ...
- 杜教BM【转载】
https://blog.csdn.net/qq_36876305/article/details/80275708 #include <bits/stdc++.h> using name ...
- ScaleIO 1.32现在可以免费下载安装使用了(除生产环境之外)
EMC World 2015会上宣布, ScaleIO 1.32可以免费下载使用在非生产环境上了. 这个可以免费下载的版本叫做Free and Drictionless (F&F) downl ...