欢迎来到天天文库
浏览记录
ID:39467782
大小:31.00 KB
页数:3页
时间:2019-07-04
《Remoting技术笔记》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Remoting技术笔记(心得体会)Remoting技术是一种产生远程对象,运用远程对象进行调用远程资料的一种技术。编写remoting程序可以分为三步,为下面1231.定义一个远程对象类这个类只能在远程服务器端生成一个实例,客户端获得这个远程对象的引用。定义远程对象类必须从MarshalByRefObject继承。在客户端可以用new来产生一个实例,但要注意,这个实例并不在客户端产生,而是在服务器端产生,在客户端只是一个引用。2、服务器端(1)注册一个通道(有两个内置通道http和tcp)Us
2、ingSystem.Runtime.Remoting.Channels.Tcp;TcpChanneltcpChannel=newTcpChannel(8085);ChannelServices.RegisterChannel(tcpChannel);(2)注册远程对象类UsingSystem.Runtime.Remoting;A(服务器激活模式)RemotingConfiguration.RegisterWellKnownServiceType(typeof(ReomotingObject.My
3、Object),"MyWeb",WellKnownObjectMode.Singleton);B(客户端激活模式)RemotingConfiguration.ApplicationName="MyWeb";RemotingConfiguration.RegisterActivatedServiceType(typeof(ReomotingObject.MyObject));3、客户端(1)注册一个通道TcpChanneltcpChannel=newTcpChannel();ChannelServ
4、ices.RegisterChannel(tcpChannel);(2)产生远程对象A、服务器端激活模式(只能调用默认构造函数):法一:ReomotingObject.MyObjectob=(ReomotingObject.MyObject)Activator.GetObject(typeof(ReomotingObject.MyObject),"tcp://localhost:8085/MyWeb");法二:System.Runtime.Remoting.RemotingConfigurati
5、on.RegisterWellKnownClientType(typeof(ReomotingObject.MyObject),"tcp://localhost:8085/MyWeb");ReomotingObject.MyObjectob=newReomotingObject.MyObject();注:只能调用默认构造函数B、客户端激活模式(可调用自定义构造函数)System.Runtime.Remoting.RemotingConfiguration.RegisterActivatedCli
6、entType(typeof(ReomotingObject.MyObject),"tcp://localhost:8085/MyWeb");ReomotingObject.MyObjectob=newReomotingObject.MyObject(1);4、总结服务器端激活模式下有singlecall和singleton两种,其中singleton只在服务器端产生一个实例,而singlecall每次都产生一个实例。客户端激活模式下也是每次都产生一个实例。值得注意的是实例都只在服务器端产生,在
7、客户端只是一个引用。
此文档下载收益归作者所有