IChannel和ChannelBase 每一种类型的信道都直接或者间接地实现了System.ServiceModel.Channels.IChannel接口。如下面的代码所示,IChannel仅仅具有一个唯一的GetProperty<T>方法用于返回信道具有的指定类型的属性。这个方法比较重要,因为它是探测信道是否具有某种能力或特性的一种有效的方法。比如可以通过该方法确定信道是否支持某种消息版本。 public interface IChannel : ICommunicationObject { T GetProperty<T>() where T : class; } 除了IChannel接口之外,WCF还定义了一个实现了该接口的抽象类ChannelBase。如下面的代码片段所示,ChannelBase不仅是CommunicationObject的子类,同时还实现了IDefaultCommunicationTimeouts接口。 public abstract class ChannelBase : CommunicationObject, IChannel, ICommunicationObject, IDefaultCommunicationTimeouts { //其他成员 public virtual T GetProperty<T>() where T : class; protected ChannelBase(ChannelManagerBase channelManager); TimeSpan IDefaultCommunicationTimeouts.CloseTimeout { get; } TimeSpan IDefaultCommunicationTimeouts.OpenTimeout { get; } TimeSpan IDefaultCommunicationTimeouts.ReceiveTimeout { get; } TimeSpan IDefaultCommunicationTimeouts.SendTimeout { get; } } ChannelBase具有一个包含ChannelManagerBase类型参数的构造函数。通过上面的介绍我们知道,ChannelManagerBase同样实现了接口IDefaultCommunicationTimeouts。当基于某个信道管理器(信道监听器或者信道工厂)创建一个信道的时候,指定的信道管理器的4个XxxTimeout属性值将默认作为信道的同名属性值。