[Remoting] 十二:配置文件(收藏转帖http://www.rainsts.net/article.asp?id=420)
来源:互联网 发布:湖南软件评测中心学费 编辑:程序博客网 时间:2024/04/30 03:33
使用配置文件替代硬编码可使应用程序拥有更高的灵活性,尤其是对分布式系统而言,意味着我们可以非常方便地调整分布对象的配置。Remoting 的配置文件比较简单,详细信息可以参考 MSDN。
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.chs/dv_fxgenref/html/52ebd450-de87-4a87-8bb9-6b13426fbc63.htm
下面是个简单的例子,包含了 SAO / CAO 的配置样例。
Server.cs
Client.cs
改成对应的配置文件,就是下面这个样子。
Server.config
Client.config
Server.cs
Client.cs
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.chs/dv_fxgenref/html/52ebd450-de87-4a87-8bb9-6b13426fbc63.htm
下面是个简单的例子,包含了 SAO / CAO 的配置样例。
Server.cs
BinaryClientFormatterSinkProvider cbin = new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider sbin = new BinaryServerFormatterSinkProvider();
sbin.TypeFilterLevel = TypeFilterLevel.Full;
Hashtable properties = new Hashtable();
properties["port"] = 801;
TcpChannel channel = new TcpChannel(properties, cbin, sbin);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Data), "data", WellKnownObjectMode.Singleton);
RemotingConfiguration.ApplicationName = "test";
RemotingConfiguration.RegisterActivatedServiceType(typeof(Data2));
BinaryServerFormatterSinkProvider sbin = new BinaryServerFormatterSinkProvider();
sbin.TypeFilterLevel = TypeFilterLevel.Full;
Hashtable properties = new Hashtable();
properties["port"] = 801;
TcpChannel channel = new TcpChannel(properties, cbin, sbin);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Data), "data", WellKnownObjectMode.Singleton);
RemotingConfiguration.ApplicationName = "test";
RemotingConfiguration.RegisterActivatedServiceType(typeof(Data2));
Client.cs
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(Data), "tcp://localhost:801/data");
RemotingConfiguration.RegisterActivatedClientType(typeof(Data2), "tcp://localhost:801/test");
Data data = new Data();
data.Test();
Data2 data2 = new Data2();
data2.Test();
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(Data), "tcp://localhost:801/data");
RemotingConfiguration.RegisterActivatedClientType(typeof(Data2), "tcp://localhost:801/test");
Data data = new Data();
data.Test();
Data2 data2 = new Data2();
data2.Test();
改成对应的配置文件,就是下面这个样子。
Server.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="test">
<channels>
<channel ref="tcp" port="801">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
<service>
<wellknown mode="Singleton" type="Learn.Library.Remoting.Data, Learn.Library" objectUri="data" />
<activated type="Learn.Library.Remoting.Data2, Learn.Library" />
</service>
</application>
</system.runtime.remoting>
</configuration>
<configuration>
<system.runtime.remoting>
<application name="test">
<channels>
<channel ref="tcp" port="801">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
<service>
<wellknown mode="Singleton" type="Learn.Library.Remoting.Data, Learn.Library" objectUri="data" />
<activated type="Learn.Library.Remoting.Data2, Learn.Library" />
</service>
</application>
</system.runtime.remoting>
</configuration>
Client.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
</channel>
</channels>
<client url="tcp://localhost:801/test">
<wellknown type="Learn.Library.Remoting.Data, Learn.Library" url="tcp://localhost:801/data" />
<activated type="Learn.Library.Remoting.Data2, Learn.Library" />
</client>
</application>
</system.runtime.remoting>
</configuration>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
</channel>
</channels>
<client url="tcp://localhost:801/test">
<wellknown type="Learn.Library.Remoting.Data, Learn.Library" url="tcp://localhost:801/data" />
<activated type="Learn.Library.Remoting.Data2, Learn.Library" />
</client>
</application>
</system.runtime.remoting>
</configuration>
Server.cs
RemotingConfiguration.Configure("server.config", false);
Client.cs
RemotingConfiguration.Configure("client.config", false);
Data data = new Data();
data.Test();
Data2 data2 = new Data2();
data2.Test();
Data data = new Data();
data.Test();
Data2 data2 = new Data2();
data2.Test();
- [Remoting] 十二:配置文件(收藏转帖http://www.rainsts.net/article.asp?id=420)
- [Remoting] 五:信道(收藏转帖http://www.rainsts.net/article.asp?id=412)
- [Remoting] 十一:事件(收藏转帖http://www.rainsts.net/article.asp?id=419)
- NET Remoting一,二(收藏转帖http://www.rainsts.net/article.asp?id=408)
- [Remoting] 三:激活模式(收藏转帖http://www.rainsts.net/article.asp?id=410)
- [Remoting] 四:生存期租约(收藏转帖http://www.rainsts.net/article.asp?id=411)
- [Remoting] 六:异步调用(收藏转帖http://www.rainsts.net/article.asp?id=413)
- [Remoting] 七:调用上下文(收藏转帖http://www.rainsts.net/article.asp?id=414)
- [Remoting] 八:元数据(收藏转帖http://www.rainsts.net/article.asp?id=415)
- [Remoting] 九:动态发布(收藏转帖http://www.rainsts.net/article.asp?id=416)
- [Remoting] 十:追踪服务(收藏转帖http://www.rainsts.net/article.asp?id=417)
- Message Queuing(收藏转帖http://www.rainsts.net/article.asp?id=418)
- 动态调用 WebService (收藏转贴http://www.rainsts.net/article.asp?id=304)
- [ASP.NET 优化] IIS6 Gziphttp://www.rainsts.net/article.asp?id=531
- 从雨痕老大的博客上转来的 http://www.rainsts.net/article.asp?id=1066 读书人偷书不算窃 :)
- asp.net控件开发基础 来源:http://www.clingingboy.com/blog/article.asp?id=258
- WebConfirm控件(转自http://www.evget.com/view/article/viewArticle.asp?article=961)
- WebConfirm控件(转自http://www.evget.com/view/article/viewArticle.asp?article=961)
- Linux 与你同行!
- [Remoting] 十:追踪服务(收藏转帖http://www.rainsts.net/article.asp?id=417)
- Message Queuing(收藏转帖http://www.rainsts.net/article.asp?id=418)
- (转)QNX-从4到6简单入门
- [Remoting] 十一:事件(收藏转帖http://www.rainsts.net/article.asp?id=419)
- [Remoting] 十二:配置文件(收藏转帖http://www.rainsts.net/article.asp?id=420)
- 用javascript动态调整iframe高度【兼容ie&FF】【转】
- 开博客
- 中午了
- .NET开源项目
- CLucene开发杂记(1)
- 数据库设计心得
- 无法创建DOMDocument对象,请检查是否安装了MS XML Parser 运行库!
- 保护你的DLL和Code不被别人使用