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 物件,而其中每一個物件都會與該服務的不同接聽程式 (Listener) 和接聽 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 物件、IChannelListenerServiceHost、目前相關聯的物件和 InstanceContextIn 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

取得或設定異動的預設隔離等級 (Isolation Level)。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()

取得目前執行個體的 TypeGets 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)

適用於