信道(Channel)是 Remoting 体系的承载平台,负责处理客户端和服务器之间的通讯,其内容包括跨域通讯、消息传递、对象编码等等。信道必须实现 IChannel 接口,根据通讯方向又分别提供了继承版本 IChannelReceiver 和 IChannelSender。Remoting 框架为我们提供了 IPC、TCP 以及 HTTP 的实现版本,当然我们还可以在网络上找到其他协议的实现版本。TcpServerChannel channel = new TcpServerChannel(801);ChannelServices.RegisterChannel(channel, false);我们可以使用实用类 ChannelServices 来管理程序域内的信道,诸如注册、注销等等。程序域内可以同时使用多个信道,每个信道需提供唯一的名称,以便 ChannelServices 进行管理,同时信道会随程序域的退出自动销毁。TcpServerChannel channel = new TcpServerChannel("tcp801", 801);ChannelServices.RegisterChannel(channel, false);IChannel c2 = ChannelServices.GetChannel("tcp801");Console.WriteLine(Object.ReferenceEquals(channel, c2));channel.StopListening(null);channel.StartListening(null);foreach (IChannel c in ChannelServices.RegisteredChannels) 信道内的接收器是可 "插入的",这意味着我们可以实现自己的接收器,并将其装配到信道接收链中。比如对消息进行加密,或者对数据流进行压缩等等。有关细节可参考:《.NET Remoting Customization Made Easy: Custom Sinks》《如何定制Sink扩展.Net Remoting功能》 相关文章: