ChannelDispatcher.Detach(ServiceHostBase) 方法

定義

從通道發送器中斷服務主機的連結。Detaches the service host from the channel dispatcher.

protected:
 override void Detach(System::ServiceModel::ServiceHostBase ^ host);
protected override void Detach (System.ServiceModel.ServiceHostBase host);
override this.Detach : System.ServiceModel.ServiceHostBase -> unit
Protected Overrides Sub Detach (host As ServiceHostBase)

參數

host
ServiceHostBase

服務的 ServiceHostBaseThe ServiceHostBase for the service.

例外狀況

hostnullhost is null.

host 不是通道發送器的主機。host is not the host of the channel dispatcher.

-或--or-

通訊物件處於 OpeningOpened 狀態中。The communication object is in an Opening or Opened state.

通訊物件處於 ClosingClosed 狀態中。The communication object is in a Closing or Closed state.

通訊物件處於 Faulted 狀態中。The communication object is in a Faulted state.

範例

Uri baseAddress = new Uri("http://localhost:8001/Simple");
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

serviceHost.AddServiceEndpoint(
    typeof(ICalculator),
    new WSHttpBinding(),
    "CalculatorServiceObject");

serviceHost.Open();

IChannelListener icl = serviceHost.ChannelDispatchers[0].Listener;
ChannelDispatcher dispatcher = new ChannelDispatcher(icl);
dispatcher.CloseInput();
Dim baseAddress As New Uri("http://localhost:8001/Simple")
Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)

serviceHost.AddServiceEndpoint(GetType(ICalculator), New WSHttpBinding(), "CalculatorServiceObject")

serviceHost.Open()

Dim icl As IChannelListener = serviceHost.ChannelDispatchers(0).Listener
Dim dispatcher As New ChannelDispatcher(icl)
dispatcher.CloseInput()

備註

ServiceHostBase 只有在 ChannelDispatcher 的執行個體處於 Created 狀態時才可以進行中斷,因為這是唯一同時處於可變動且尚未處置的狀態。The ServiceHostBase can only be detached when the instance of the ChannelDispatcher is in the Created state, as this is the only state that is both mutable and not disposed.

將與通道發送器關聯的 ServiceHostBase 設定為 nullSets the ServiceHostBase associated with the channel dispatcher to null.

適用於