区别:
RMI的客户端和服务端都必须是java,webservice没有这个限制
webservice是在http协议上传递xml文本文件,与语言和平台无关
RMI是在tcp协议上传递可序列化的java对象,只能用在java虚拟机上,绑定语言
RMI是EJB远程调用的基础,仅用RMI技术就可以实现远程调用,使用EJB是为了实现组件,事物,资源池,集群等功能。
WebService是通过XML来传输数据,可用http等协议因此可在异构系统间传递,并且可以穿过防火墙,可在公网上远程调用
协作:
一、一些概念
WebService技术现在几乎无处不在,以前玩.NET的时候最开始接触这个概念,C#语言对WebService近似原生性的支持使我们用C#可以非常迅速的开发出一个WebService,没有任何复杂烦扰的步骤。
后来没有机会再在.Net Framework上面开发,转投了Java的怀抱,想要开发出一个WebService感觉比较,搞一堆命令生成一堆什么代码,好不容易才能搭出来,尝试一次之后终于还是放弃了,觉得麻烦。
Java6.0出来之后对WebService也说原生支持了,所以再做毕业设计的时候想到体验一下Java6.0的WebService,果然容易上手很多,易用。毕业设计把这个计算在内,智能设备+WebService可以作为系统应用的一部分。
开始代码之前先大概说说我对这几个概念的理解
WebService 是分布式应用程序组件,这么说可能太抽象,这其实以经不是一个新的概念了,但是突然间要解释这个名次还比较不容易。它其实是构建在已有技术基础上的一个概 念,WebService的核心是xml、soap、wsdl等,客户可以通过web请求的方式使用WebService。或者说得更通俗点就是服务提供 商把他提供的服务发布到Internet上,然后客户可以通过Internet使用这个服务。
RMI这个东西上手也不那么容易, 不过这个概念可以简单点来理解,就是不同JVM之间通讯的一个手段,这里调用的是Java代码。不同的JVM可以在不同的机器上或者是同一台机器上。这个 纯Java的分布式应用的一个典型的Solution. RMI技术和CORBA互为补充。
对于CORBA我没有详细学习过,不过概念很容易懂,CORBA 允许应用程序和其他的应用程序通讯,而不论他们在什么地方或者由谁来设计。CORBA和语言实现是无关的,C++和Java实现的系统通过CORBA通信。EMA里面就有这个CORBA。
二、协作的需求模型
下面切入正题,说说WebService和RMI的协作。我们先来看这个需求的模型是怎么样的。看下图
系统要求有Smart device对远程的JVM2里的程序控制,所以我们引入了WebService,通过WebService间接调用JVM2里的东 西,WebSerivce本身运行在JVM1,JVM1和JVM2可以在不同机器上,这里demo程序是在一台机器上运行的。
WebService在这里既是SmartDevice的Server端,又是RMI的Client端。RMI的Server端在JVM2的App里作为一部分服务存在。
三、代码分解,下面我们开始demo这个协作的代码
3.1 首先我们抽象一个RMI的Interface













简单的接口,一个是获得时间的,一个是获取随便什么消息的接口
3.2实现RMI的Server端



























































3.3我们可以先写个RMI的Client测试一下































由于在本机上,省略了ip什么的,如果对这段代码不是很懂,建议看后面的参考资料
测试方法,先运行Server,再运行Client,不出以外,你能看到2008年5月10号。
3.4我们开始实现我们的WebService Server端
Java6.0实现WebService也很简单,我直接贴代码了。Server端如下,如果不太懂,还是建议看后面的参考资料





























































3.6实现WebService的客户端
首先cd到src目录,然后敲wsimport -keep http://localhost:8435/MyTimeServer?wsdl这个会自动生成一堆代码,基本上可以理解为stub一类的东西
然后我们就可以直接调用啦























到此为止,这个WebService和RMI的协作完成了,代码尽量精简了
相关推荐
WSDL文件包含了服务的位置、使用的消息协议以及如何调用服务的方法,使得客户端能够找到并理解如何与服务进行交互。 3. **UDDI(Universal Description, Discovery, and Integration)**:这是一个标准的目录服务,...
1. **体系结构设计**:设计一种基于Web Service 的工作流管理系统的体系结构,确保各个模块的功能和实现方法能够支持分布式环境下的高效协作。 2. **模块功能描述**:详细描述各个模块的具体功能,如工作流引擎、...
**XML (Extensible Markup Language)**与**HTML (HyperText Markup Language)**的主要区别在于XML设计用于传输和存储数据,而HTML主要用于展示数据。XML与JSP的集成方案,如使用XML作为数据源,通过JSP处理并呈现给...
综上,软件工程师面试中涉及的知识点包括MVC设计模式的理论及应用,Struts框架的工作原理,WebService的定义、特点和工作流程,以及中间件的概念、分类和作用。这些知识点是Web开发领域的核心概念,理解和掌握它们...
1. 微服务架构与单体架构的区别和优势。微服务架构相较于单体架构而言,具有职责单一、解耦、独立部署、异构、以及扩缩容等特点。在单体架构中,应用实施简单,接口少,容易部署,但其耦合度高、可维护性差、稳定性...
### Java面试题及答案解析 #### 一、MVC架构的理解与应用 **问题:** 对于MVC的理解,MVC有什么优缺点? **解答:** MVC(Model-View-Controller)是一种常用的设计模式,主要用于简化应用程序开发过程中的复杂度...
16. **版本控制与协作**:熟悉Git或SVN等版本控制系统,理解分支策略和代码合并流程,适应团队协作开发。 17. **敏捷开发与项目管理**:理解敏捷开发方法(如Scrum、Kanban),掌握项目管理工具(如JIRA、Trello)...
视图通常是用户看到并与之互动的一切内容。它可以是任何显示数据的方法,比如HTML页面或图形用户界面。 - **控制器(Controller)**:这部分负责处理用户的输入,并将其转换为对模型或视图的操作。它接收来自用户的...
以上总结了J2EE架构下的多个关键知识点,涵盖了类实例化、接口与抽象类的区别、数据结构、Servlet、Web应用架构、EJB角色、XML解析、WebService以及线程模型等方面,旨在帮助准备面试和笔试的开发者巩固对J2EE核心...
2. **WebService概念及工作原理** WebService是一种基于开放标准(如WSDL、SOAP和UDDI)的SOA架构,允许不同平台、语言的应用程序通过Internet互相通信。其基本流程如下: - **服务提供者** 使用WSDL描述服务,...
SOAP(Simple Object Access Protocol)是一种常见的WebService协议,通常与WSDL(Web Services Description Language)一起使用来定义服务接口。 8. Filter和`ContextLoaderListener`: 在Servlet容器中,`...
- **RMI 和 RPC 的区别** - **RMI (Remote Method Invocation)**:是 Java 特有的远程调用协议,允许客户端直接调用远程服务器上的对象方法。 - **RPC (Remote Procedure Call)**:是一种通用的远程过程调用协议,...
同时也支持传统的RMI、Hessian、WebService等技术栈。 **服务动态发现**:在分布式环境中,服务实例可能会频繁上下线,因此需要一种机制来动态地管理和跟踪这些服务实例的状态。Dubbo支持通过Zookeeper或Redis等...
MVC模式使得应用易于理解、修改和测试,每个部分都有明确的责任划分,便于团队协作开发。 #### 二、J2EE概述 J2EE(Java 2 Platform, Enterprise Edition)是由Sun Microsystems公司提出的多层分布式企业级应用模型...
同时,架构师还需要关注到软件系统的各个细节,例如进程内通信(对象访问、函数调用、数据交换、线程同步等)以及进程外通信(RMI、DCOM、WebService等)。 架构设计的决策过程往往需要采用至上而下的分析方法,将...
例如,对于.NET平台,理解CLR、继承特性、委托和事件处理等基础知识,以及ASP.NET WebService、.NET Remoting和企业服务组件的应用,是架构设计的基础。 除了技术能力,行业业务知识同样关键。架构师需要深入理解所...
他们需要在项目初期就对整个软件系统的规划、开发、维护和变更进行整体把握,考虑技术选型、团队协作、沟通策略、市场需求以及环境适应性等多个方面。架构设计涉及的问题分解,包括横向和纵向的模块划分,关注点分离...
此外,还要掌握JavaWeb分布式开发技术,包括JTA事务管理、JAAS验证与授权服务、JNDI命名与目录服务、JavaMail邮件服务、JMS信息服务,以及WebService、JCA、JMX等。 最后,作为JavaEE系统架构师,需要关注面向云...
C/S(Client/Server)与B/S(Browser/Server)两种架构的主要区别在于: 1. **硬件环境**:C/S架构通常建立在专用的网络上,适用于固定的小范围局域网环境;而B/S架构建立在广域网上,具有更强的适应性,只需要操作...
5. **JavaScript**:掌握JavaScript的基本语法和DOM操作,它是前端交互的关键,也能辅助理解后端与前端的协作。 6. **数据库优化**:理解数据库优化技术,包括索引、查询优化和数据库集群,这是提高系统性能的重要...