ChannelDispatcher 类
定义
接受通道以及将通道与服务相关联的组件。A component that accepts channels and associates them with a service.
public ref class ChannelDispatcher : System::ServiceModel::Dispatcher::ChannelDispatcherBase
public class ChannelDispatcher : System.ServiceModel.Dispatcher.ChannelDispatcherBase
type ChannelDispatcher = class
inherit ChannelDispatcherBase
Public Class ChannelDispatcher
Inherits ChannelDispatcherBase
- 继承
示例
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();
Dim baseAddress As New Uri("http://localhost:8001/Simple")
Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)
serviceHost.AddServiceEndpoint(GetType(ICalculator), New WSHttpBinding(), "CalculatorServiceObject")
' Enable MEX.
Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
serviceHost.Description.Behaviors.Add(smb)
serviceHost.Open()
Dim icl As IChannelListener = serviceHost.ChannelDispatchers(0).Listener
Dim dispatcher As New ChannelDispatcher(icl)
Console.WriteLine("servicehost has {0} ChannelDispatchers", serviceHost.ChannelDispatchers.Count)
Dim dispatchers As ChannelDispatcherCollection = serviceHost.ChannelDispatchers
For Each disp As ChannelDispatcher In dispatchers
Console.WriteLine("Binding name: " & disp.BindingName)
Next disp
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()
注解
ChannelDispatcher 对象将在特定 URI(称为侦听 URI)的 IChannelListener 与服务的实例相关联。A ChannelDispatcher object associates an IChannelListener at a particular URI (called a listen URI) with an instance of a service. 每个 ServiceHost 对象都可以拥有多个 ChannelDispatcher 对象,这多个对象每个都可与该服务的不同侦听器和侦听 URI 相关联。Each ServiceHost object can have many ChannelDispatcher objects, each associated with a different listener and listen URI for that service.
当消息到达时,ChannelDispatcher 会查询每个相关的 EndpointDispatcher 对象以确定终结点是否可以接受消息,并将该消息传递到可以接受消息的终结点。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. 当消息的目标地址与 EndpointDispatcher 属性相匹配并且消息操作与 ChannelDispatcher 属性相匹配时,AddressFilter 对象负责处理来自 ContractFilter 的消息。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.
控制通道会话的生存期和行为的所有属性都可以在 ChannelDispatcher 对象上检查或修改。All properties that control the lifetime and behavior of a channel session are available for inspection or modification on the ChannelDispatcher object. 除了 EndpointDispatcher 之外,这些属性还包括自定义 IChannelInitializer 对象、IChannelListener、ServiceHost 以及相关的 InstanceContext。In addition to the EndpointDispatcher, these include custom IChannelInitializer objects, the IChannelListener, the ServiceHost, the associated and InstanceContext.
构造函数
| ChannelDispatcher(IChannelListener) |
初始化 ChannelDispatcher 类的新实例。Initializes a new instance of the ChannelDispatcher class. |
| ChannelDispatcher(IChannelListener, String) |
初始化 ChannelDispatcher 类的新实例。Initializes a new instance of the ChannelDispatcher class. |
| ChannelDispatcher(IChannelListener, String, IDefaultCommunicationTimeouts) |
初始化 ChannelDispatcher 类的新实例。Initializes a new instance of the ChannelDispatcher class. |
属性
| AsynchronousTransactedAcceptEnabled |
获取一个值,该值指示侦听程序上的事务处理接受方法调用是否为异步。Gets a value that indicates whether the transacted accept method calls on listener are asynchronous. |
| BindingName |
获取用于配置服务的绑定的名称。Gets the name of the binding used to configure the service. |
| ChannelInitializers |
获取 IChannelInitializer 对象的集合,在首次创建通道时您可以使用这些对象来检查通道以及向通道添加状态。Gets a set of IChannelInitializer objects that you can use to inspect and add state to channels when they are first created. |
| DefaultCloseTimeout |
获取为关闭通道调度程序预留的默认时间间隔。Gets the default interval of time allowed for the channel dispatcher to close. |
| DefaultOpenTimeout |
获取为打开通道调度程序预留的默认时间间隔。Gets the default interval of time allowed for the channel dispatcher to open. |
| Endpoints |
获取将消息转发到通道终结点的终结点调度程序。Gets the endpoint dispatchers which forward messages to the channel endpoints. |
| ErrorHandlers |
获取 IErrorHandler 对象的集合,这些对象可用于插入终结点的自定义错误处理功能。Gets a set of IErrorHandler objects that can be used to insert custom error handling functionality for an endpoint. |
| Host |
获取与调度程序关联的服务的宿主。Gets the host for the service associated with the dispatcher. |
| IncludeExceptionDetailInFaults |
获取或设置一个值,该值指示是否在错误中包含有关异常的详细信息。Gets or sets a value that indicates whether to include the details about an exception in a fault. |
| IsDisposed |
获取一个值,该值指示通信对象是否已被释放。Gets a value that indicates whether the communication object has been disposed. (继承自 CommunicationObject) |
| IsTransactedAccept |
获取一个值,该值指示对侦听程序的接受方法调用是否在事务中完成。Gets a value that indicates whether the accept method calls on the listener are done under a transaction. |
| IsTransactedReceive |
获取一个值,该值指示对侦听程序的接收方法调用是否在事务中完成。Gets a value that indicates whether the receive method calls on the listener are done under a transaction. |
| Listener |
获取与通道调度程序关联的侦听程序。Gets the listener associated with the channel dispatcher. |
| ManualAddressing |
获取或设置一个值,该值指示通道调度程序是否将寻址标头添加到请求-回复消息。Gets or sets a value that indicates whether the channel dispatcher adds addressing headers to request-reply messages. |
| MaxPendingReceives |
获取或设置每个通道的最大挂起消息数。Gets or sets the maximum pending messages per channel. |
| MaxTransactedBatchSize |
获取或设置事务处理批处理的最大大小。Gets or sets the maximum size for a transacted batch. |
| MessageVersion |
获取或设置使用的或预期的 SOAP 消息和 WS-Addressing 版本。Gets or sets the SOAP message and WS-Addressing versions that are used or expected. |
| ReceiveContextEnabled |
获取或设置是否启用 ReceiveContext。Gets or sets whether ReceiveContext is enabled. |
| ReceiveSynchronously |
获取或设置一个值,该值指定调度程序是否使用同步调用从通道读取消息。Gets or sets a value that specifies whether the dispatcher uses synchronous calls to read messages from channels. |
| SendAsynchronously |
获取或设置是否异步发送消息。Gets or sets whether messages are sent asynchronously. |
| ServiceThrottle |
获取或设置与通道调度程序关联的服务的服务控制器。Gets or sets the service throttle for the service associated with the channel dispatcher. |
| State |
获取指示通信对象当前状态的值。Gets a value that indicates the current state of the communication object. (继承自 CommunicationObject) |
| ThisLock |
获取在状态转换过程中保护类实例的相互排斥锁。Gets the mutually exclusive lock that protects the class instance during a state transition. (继承自 CommunicationObject) |
| TransactionIsolationLevel |
获取或设置事务的默认隔离级别。Gets or sets the default isolation level for transactions. |
| TransactionTimeout |
获取或设置由代表该服务的调度程序创建的新事务的默认超时值。Gets or sets a value that specifies the default timeout for new transactions created by the dispatcher on behalf of the service. |
方法
| Abort() |
使通信对象立即从其当前状态转换到正在关闭状态。Causes a communication object to transition immediately from its current state into the closing state. (继承自 CommunicationObject) |
| Attach(ServiceHostBase) |
将通道调度程序附加到宿主。Attaches the channel dispatcher to the host. |
| BeginClose(AsyncCallback, Object) |
开始一个异步操作以关闭通信对象。Begins an asynchronous operation to close a communication object. (继承自 CommunicationObject) |
| BeginClose(TimeSpan, AsyncCallback, Object) |
开始一个异步操作以在指定超时内关闭通信对象。Begins an asynchronous operation to close a communication object with a specified timeout. (继承自 CommunicationObject) |
| BeginOpen(AsyncCallback, Object) |
开始一个异步操作以打开通信对象。Begins an asynchronous operation to open a communication object. (继承自 CommunicationObject) |
| BeginOpen(TimeSpan, AsyncCallback, Object) |
开始一个异步操作以在指定时间间隔内打开通信对象。Begins an asynchronous operation to open a communication object within a specified interval of time. (继承自 CommunicationObject) |
| Close() |
使通信对象从其当前状态转换到关闭状态。Causes a communication object to transition from its current state into the closed state. (继承自 CommunicationObject) |
| Close(TimeSpan) |
使通信对象在指定时间间隔内从当前状态转换到关闭状态。Causes a communication object to transition from its current state into the closed state within a specified interval of time. (继承自 CommunicationObject) |
| CloseInput() |
阻止侦听程序接受新通道。Stops the listener from accepting new channels. |
| Detach(ServiceHostBase) |
将服务主机与通道调度程序分离。Detaches the service host from the channel dispatcher. |
| EndClose(IAsyncResult) |
完成一个异步操作以关闭通信对象。Completes an asynchronous operation to close a communication object. (继承自 CommunicationObject) |
| EndOpen(IAsyncResult) |
完成一个异步操作以打开通信对象。Completes an asynchronous operation to open a communication object. (继承自 CommunicationObject) |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| Fault() |
使通信对象从其当前状态转换到出错状态。Causes a communication object to transition from its current state into the faulted state. (继承自 CommunicationObject) |
| GetCommunicationObjectType() |
获取通信对象的类型。Gets the type of communication object. (继承自 CommunicationObject) |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| OnAbort() |
中止与调度程序关联的侦听程序。Aborts the listener associated with the dispatcher. |
| OnBeginClose(TimeSpan, AsyncCallback, Object) |
开始必须在指定时间间隔内完成的异步操作,来关闭调度程序的通道侦听程序。Begins an asynchronous operation to close a channel listener for the dispatcher that must be completed within a specified interval of time. |
| OnBeginOpen(TimeSpan, AsyncCallback, Object) |
开始必须在指定时间间隔内完成的异步操作,来打开调度程序的通道侦听程序。Begins an asynchronous operation to open a channel listener for the dispatcher that must be completed within a specified interval of time. |
| OnClose(TimeSpan) |
在指定的时间间隔内关闭与调度程序关联的通道侦听程序。Closes the channel listener associated with the dispatcher within a specified interval of time. |
| OnClosed() |
提供对关闭与通道调度程序关联的终结点调度程序的跟踪。Provides a trace of the closing of the endpoint dispatchers associated with the channel dispatcher. |
| OnClosing() |
在通信对象转换到正在关闭状态的过程中被调用。Invoked during the transition of a communication object into the closing state. (继承自 CommunicationObject) |
| OnEndClose(IAsyncResult) |
完成异步操作来关闭调度程序的通道侦听程序。Completes an asynchronous operation to close a channel listener for the dispatcher. |
| OnEndOpen(IAsyncResult) |
完成异步操作来打开调度程序的通道侦听程序。Completes an asynchronous operation to open a channel listener for the dispatcher. |
| OnFaulted() |
在调用了同步错误操作,从而引起通信对象转换为出错状态的情况下,该方法插入对通信对象的处理。Inserts processing on a communication object after it transitions to the faulted state due to the invocation of a synchronous fault operation. (继承自 CommunicationObject) |
| OnOpen(TimeSpan) |
打开与通道调度程序关联的侦听程序。Opens the listener associated with the channel dispatcher. |
| OnOpened() |
填充和验证用于调度到终结点的筛选器表。Populates and validates filter table used to dispatch to the endpoints. |
| OnOpening() |
检查通道调度程序是否附加到宿主。Checks whether the channel dispatcher is attached to a host. |
| Open() |
使通信对象从已创建状态转换到已打开状态。Causes a communication object to transition from the created state into the opened state. (继承自 CommunicationObject) |
| Open(TimeSpan) |
使通信对象在指定时间间隔内从已创建状态转换到已打开状态。Causes a communication object to transition from the created state into the opened state within a specified interval of time. (继承自 CommunicationObject) |
| ThrowIfDisposed() |
如果通信对象已释放,则引发异常。Throws an exception if the communication object is disposed. (继承自 CommunicationObject) |
| ThrowIfDisposedOrImmutable() |
如果通信对象的 State 属性未设置为 Created 状态,则引发异常。Throws an exception if the communication object the State property is not set to the Created state. (继承自 CommunicationObject) |
| ThrowIfDisposedOrNotOpen() |
如果通信对象未处于 Opened 状态,则引发异常。Throws an exception if the communication object is not in the Opened state. (继承自 CommunicationObject) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
事件
| Closed |
当通信对象转换到已关闭状态时发生。Occurs when a communication object transitions into the closed state. (继承自 CommunicationObject) |
| Closing |
当通信对象转换到正在关闭状态时发生。Occurs when a communication object transitions into the closing state. (继承自 CommunicationObject) |
| Faulted |
在通信对象转换到出错状态时发生。Occurs when a communication object transitions into the faulted state. (继承自 CommunicationObject) |
| Opened |
当通信对象转换到已打开状态时发生。Occurs when a communication object transitions into the opened state. (继承自 CommunicationObject) |
| Opening |
当通信对象转换到正在打开状态时发生。Occurs when a communication object transitions into the opening state. (继承自 CommunicationObject) |