ChannelDispatcher Class

A component that accepts channels and associates them with a service.

Namespace:  System.ServiceModel.Dispatcher
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public class ChannelDispatcher : ChannelDispatcherBase

A ChannelDispatcher object associates an IChannelListener at a particular URI (called a listen URI) with an instance of a service. Each ServiceHost object can have many ChannelDispatcher objects, each associated with a different listener and listen URI for that service.

When a message arrives, the ChannelDispatcher queries each of the associated EndpointDispatcher objects whether the endpoint can accept the message, and passes the message to the one that can. The EndpointDispatcher object is responsible for processing messages from a ChannelDispatcher when the destination address of a message matches the AddressFilter property and the message action matches the ContractFilter property.

All properties that control the lifetime and behavior of a channel session are available for inspection or modification on the ChannelDispatcher object. In addition to the EndpointDispatcher, these include custom IChannelInitializer objects, the IChannelListener, the ServiceHost, the associated and 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();

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft