共用方式為


ChannelDispatcher.Detach(ServiceHostBase) 方法

定義

從通道發送器中斷服務主機的連結。

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

服務的 ServiceHostBase

例外狀況

hostnull

host 不是通道發送器的主機。

-或-

通訊物件處於 OpeningOpened 狀態中。

通訊物件處於 ClosingClosed 狀態中。

通訊物件處於 Faulted 狀態中。

範例

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 狀態時才可以進行中斷,因為這是唯一同時處於可變動且尚未處置的狀態。

將與通道發送器關聯的 ServiceHostBase 設定為 null

適用於