1)注册多个通道

1)注册多个通道
在 Remoting 中,允许同时创建多个通道,即根据不同的端口创建不同的通道。但是,
Remoting 要求通道的名字必须不同,因为它要用来作为通道的唯一标识符。虽然IChannel
有ChannelName 属性,但这个属性是只读的。因此前面所述的创建通道的方法无法实现同
时注册多个通道的要求。
这个时候,我们必须用到 System.Collection 中的IDictionary 接口:
注册 Tcp 通道:
IDictionary tcpProp = new Hashtable();
tcpProp["name"] = "tcp9090";
tcpProp["port"] = 9090;
IChannel channel = new TcpChannel(tcpProp,
new BinaryClientFormatterSinkProvider(),
new BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel);
注册 Http 通道:
IDictionary httpProp = new Hashtable();
httpProp["name"] = "http8080";
httpProp["port"] = 8080;
IChannel channel = new HttpChannel(httpProp,
new SoapClientFormatterSinkProvider(),
new SoapServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel);
在 name 属性中,定义不同的通道名称就可以了。

 

posted @ 2018-02-14 09:20  sky20080101  阅读(135)  评论(0)    收藏  举报