ChannelDispatcher类 相关 from msdn
ChannelDispatcher 对象将在特定 URI(称为侦听 URI)的 IChannelListener 与服务的实例相关联。 每个 ServiceHost 对象都可以拥有多个 ChannelDispatcher 对象,这多个对象每个都可与该服务的不同侦听器和侦听 URI 相关联。
当消息到达时,ChannelDispatcher 查询每个相关的 EndpointDispatcher 对象以确定终结点是否可以接受消息,以及将该消息传递到可以接受消息的终结点。 当消息的目标地址与 AddressFilter 属性相匹配并且消息操作与 ContractFilter 属性相匹配时,EndpointDispatcher 对象负责处理来自 ChannelDispatcher 的消息。
控制通道会话的生存期和行为的所有属性都可以在 ChannelDispatcher 对象上检查或修改。 除了 EndpointDispatcher 之外,这些属性还包括自定义 IChannelInitializer 对象、IChannelListener、ServiceHost 以及相关的 InstanceContext。
Uri baseAddress = new Uri("http://localhost:8001/Simple"); ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress); serviceHost.AddServiceEndpoint( typeof(ICalculator), new WSHttpBinding(), "CalculatorServiceObject"); // Enable MEX. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; serviceHost.Description.Behaviors.Add(smb); serviceHost.Open(); IChannelListener icl = serviceHost.ChannelDispatchers[0].Listener; ChannelDispatcher dispatcher = new ChannelDispatcher(icl); Console.WriteLine("servicehost has {0} ChannelDispatchers", serviceHost.ChannelDispatchers.Count); ChannelDispatcherCollection dispatchers = serviceHost.ChannelDispatchers; foreach (ChannelDispatcher disp in dispatchers) { Console.WriteLine("Binding name: " + disp.BindingName); } Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. serviceHost.Close(); }
KidYang