我所理解的Remoting(3):创建CAO Service Factory使接口和实现相互分离
2007-04-02 19:04
826 查看
我们知道对于Remoting,有两种不同的Activation模式:Server Activation和Client Activation。他我在前面的系列文章中分析、比较了这两种不同激活方式的区别:Marshaling方式,远程对象创建的时机,状态的保持,生命周期的管理。 在编程模式方面Server Activation和Client Activation也具有一定的差异:为一个SAO(server activated object)和一个CAO(client activated object)注册一个远程对象类型的方式是不同的(Wellknown Service Type Re V.S. Activated Type Registration);为为一个SAO(server activated object)和一个CAO(client activated object)创建Proxy的方式也不一样:对于SAO,一般通过Activator的静态方法GetObject(传入一个远程对象的地址);而我们一般通过new 关键字或者Activator的静态方法CreateInstance。
对于Client Activation,由于我们在创建Proxy对象的时候,必须利用远程对象对应的原数据,所以在Client端,需要引用远程的对象所对应的dll。比如我们现在做一个简单的计数器的例子(Client远程调用获得计数器当前的计数)我们把业务逻辑封装在Counter Service的实体中。下图反映了这样一种架构的依赖关系。
using System; using System.Collections.Generic; using System.Text; namespace Artech.CAOFactory.ContractICounterFactory
Step 3 实现Contract:Artech.CAOFactory.Service
CounterFactoryService
Step 3 通过IIS Host CounterFactoryService
修改编译配置把Dll生成在Project根目录的bin目录下,基于这个根目录创建虚拟目录(假设Alias就是Artech.CAOFactory),并添加Web.config。
Step 4 创建客户端Artech.CAOFactory.Client
Program
从上面的代码我们可以看到,我们希望使用的远程对象的Proxy(counter),是通过另一个SongleCall Proxy(counterFactory)获得的。
下面来运行,从输出结果来看,和我们平常使用的SAO方式的结果没有什么两样——同一个Proxy之间的调用状态被保留。
相关章节:
[原创]我所理解的Remoting(1):Marshaling & Activation - Part I
[原创]我所理解的Remoting(1):Marshaling & Activation - Part II
[原创]我所理解的Remoting(2):远程对象生命周期的管理—Part I
[原创]我所理解的Remoting (2) :远程对象的生命周期管理-Part II
[原创]我所理解的Remoting(3):创建CAO Service Factory使接口和实现相互分离
[原创].NET Remoting: 如何通过Remoting实现双向通信(Bidirectional Communication)
String remoteAddress = "http://localhost/Artech.CAOFactory/CounterFactory.rem"; ICounter counter = ICounterFactory counterFactory = (ICounterFactory)Activator.GetObject(typeof(ICounterFactory), remoteAddress);
对于Client Activation,由于我们在创建Proxy对象的时候,必须利用远程对象对应的原数据,所以在Client端,需要引用远程的对象所对应的dll。比如我们现在做一个简单的计数器的例子(Client远程调用获得计数器当前的计数)我们把业务逻辑封装在Counter Service的实体中。下图反映了这样一种架构的依赖关系。
using System; using System.Collections.Generic; using System.Text; namespace Artech.CAOFactory.ContractICounterFactory
using System; using System.Collections.Generic; using System.Text; namespace Artech.CAOFactory.Contract
Step 3 实现Contract:Artech.CAOFactory.Service
using System; using System.Collections.Generic; using System.Text; using Artech.CAOFactory.Contract; namespace Artech.CAOFactory.Service
CounterFactoryService
using System; using System.Collections.Generic; using System.Text; using Artech.CAOFactory.Contract; namespace Artech.CAOFactory.Service
Step 3 通过IIS Host CounterFactoryService
修改编译配置把Dll生成在Project根目录的bin目录下,基于这个根目录创建虚拟目录(假设Alias就是Artech.CAOFactory),并添加Web.config。
<?xml version="1.0"?> <configuration> <configSections> <section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections> <WorkflowRuntime Name="WorkflowServiceContainer"> <Services> <add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> <add type="System.Workflow.Runtime.Hosting.DefaultWorkflowCommitWorkBatchService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </Services> </WorkflowRuntime> <appSettings/> <connectionStrings/> <system.web> <compilation debug="false"/> <authentication mode="Windows"/> </system.web> <system.runtime.remoting> <application> <service> <wellknown type="Artech.CAOFactory.Service.CounterFactoryService, Artech.CAOFactory.Service" mode ="SingleCall" objectUri="CounterFactory.rem"></wellknown> </service> </application> </system.runtime.remoting> </configuration>
Step 4 创建客户端Artech.CAOFactory.Client
Program
using System; using System.Collections.Generic; using System.Text; using Artech.CAOFactory.Contract; using System.Threading; using System.Runtime.Remoting; namespace Artech.CAOFactory.Client
从上面的代码我们可以看到,我们希望使用的远程对象的Proxy(counter),是通过另一个SongleCall Proxy(counterFactory)获得的。
下面来运行,从输出结果来看,和我们平常使用的SAO方式的结果没有什么两样——同一个Proxy之间的调用状态被保留。
相关章节:
[原创]我所理解的Remoting(1):Marshaling & Activation - Part I
[原创]我所理解的Remoting(1):Marshaling & Activation - Part II
[原创]我所理解的Remoting(2):远程对象生命周期的管理—Part I
[原创]我所理解的Remoting (2) :远程对象的生命周期管理-Part II
[原创]我所理解的Remoting(3):创建CAO Service Factory使接口和实现相互分离
[原创].NET Remoting: 如何通过Remoting实现双向通信(Bidirectional Communication)
相关文章推荐
- [原创]我所理解的Remoting(3):创建CAO Service Factory使接口和实现相互分离
- “Oracle.DataAccess.Client.OracleClientFactory”未实现 IServiceProvider 接口
- 学习笔记:使用Web Service Software Factory开发简易留言本服务以及Mobile调用实现-1.创建Service
- 在Remoting客户端激活方式采用替换类以分离接口与实现
- 简单工厂(Factory)-提供一个创建对象实例的功能,而无须关心其具体实现。被创建实例的类型可以是接口、抽象类,也可以是具体的类。
- 创建执行线程的方式三:实现 Callable 接口
- 自定义类MyThread 实现Runnable接口,主函数创建5个线程,自定义线程类的构造函数输出 创建线程X -002
- C++中接口与实现分离的技术
- 再论C++中接口与实现分离的技术
- java之实现Cloneable接口的详解,克隆一个对象--对应有浅克隆和深克隆,概念结合代码深入理解
- c语言接口与实现--内存管理章节理解,含实例
- 通过实现继承TabActivity并且实现TabContentFactory的方法创建选项卡的一点心得
- Java实现app接口和Socket消息传递(9)navicat创建user表
- js创建数据共享接口——简化框架之间相互传值
- Spring-Bean的初始化(init方法和实现org.springframework.beans.factory.InitializingBean接口)
- 对“针对接口编程,而不是针对实现编程”的理解
- spring BeanFactory接口子类及其实现类
- C++中接口与实现分离技术 ,DLL导出类
- 我所理解的设计模式(C++实现)——简单工厂模式(Simple Factory Pattern)
- 09-多线程(创建线程的第二种方式—实现Runnable接口)1 2 10-多线程(第二种方式的细节) 11-多线程(第二种方式的好处)