ServiceHostBase 類別

定義

擴充 ServiceHostBase 類別以實作公開自訂程式撰寫模型的主機。Extends the ServiceHostBase class to implement hosts that expose custom programming models.

public ref class ServiceHostBase abstract : System::ServiceModel::Channels::CommunicationObject, IDisposable, System::ServiceModel::IExtensibleObject<System::ServiceModel::ServiceHostBase ^>
public abstract class ServiceHostBase : System.ServiceModel.Channels.CommunicationObject, IDisposable, System.ServiceModel.IExtensibleObject<System.ServiceModel.ServiceHostBase>
type ServiceHostBase = class
    inherit CommunicationObject
    interface IExtensibleObject<ServiceHostBase>
    interface IDisposable
Public MustInherit Class ServiceHostBase
Inherits CommunicationObject
Implements IDisposable, IExtensibleObject(Of ServiceHostBase)
繼承
ServiceHostBase
衍生
實作

範例

這個範例會使用衍生自 ServiceHostServiceHostBase 類別。This sample uses the ServiceHost class, which is derived from ServiceHostBase.

// Host the service within this EXE console application.
public static void Main()
{
  using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
  {
    try
    {
      // Open the ServiceHost to start listening for messages.
      serviceHost.Open();

        // The service can now be accessed.
      Console.WriteLine("The service is ready.");
      Console.WriteLine("Press <ENTER> to terminate service.");
      Console.ReadLine();

      // Close the ServiceHost.
      serviceHost.Close();
    }
    catch (TimeoutException timeProblem)
    {
      Console.WriteLine(timeProblem.Message);
      Console.ReadLine();
    }
    catch (CommunicationException commProblem)
    {
      Console.WriteLine(commProblem.Message);
      Console.ReadLine();
    }
  }
}
' Host the service within this EXE console application.
Public Shared Sub Main()
    ' Create a ServiceHost for the CalculatorService type and use the base address from config.
    Using svcHost As New ServiceHost(GetType(CalculatorService))
        Try
            ' Open the ServiceHost to start listening for messages.
            svcHost.Open()

            ' The service can now be accessed.
            Console.WriteLine("The service is ready.")
            Console.WriteLine("Press <ENTER> to terminate service.")
            Console.WriteLine()
            Console.ReadLine()

            'Close the ServiceHost.
            svcHost.Close()

        Catch timeout As TimeoutException
            Console.WriteLine(timeout.Message)
            Console.ReadLine()
        Catch commException As CommunicationException
            Console.WriteLine(commException.Message)
            Console.ReadLine()
        End Try
    End Using

End Sub

備註

您可以使用 ServiceHostBase 類別建立提供自訂程式設計模型的主機。Use the ServiceHostBase class to create hosts that provide a custom programming model. Windows Communication Foundation (WCF)服務程式設計模型會使用ServiceHost類別。The Windows Communication Foundation (WCF) service programming model uses the ServiceHost class.

給衍生自此類別之 Managed C++ 使用者的特別說明:Special note for Managed C++ users deriving from this class:

  • 請將您的清除程式碼置於 (On)(Begin)Close (and/or OnAbort),而不是解構函式。Put your cleanup code in (On)(Begin)Close (and/or OnAbort), not in a destructor.

  • 避免使用解構函式,因為它們會導致編譯器自動產生 IDisposableAvoid destructors; they cause the compiler to auto-generate IDisposable.

  • 避免使用非參考成員,因為它們會導致編譯器自動產生 IDisposableAvoid non-reference members; they can cause the compiler to auto-generate IDisposable.

  • 避免使用完成項,但如果您要加入完成項,則應隱藏建置警告並從 (On)(Begin)Close (和/或 OnAbort) 呼叫 SuppressFinalize(Object)IDisposable和完成項本身,以模擬原本可能自動產生的 行為。Avoid finalizers; but if you include one, you should suppress the build warning and call SuppressFinalize(Object) and the finalizer itself from (On)(Begin)Close (and/or OnAbort) to emulate what would have been the auto-generated IDisposable behavior.

建構函式

ServiceHostBase()

初始化 ServiceHostBase 類別的新執行個體。Initializes a new instance of the ServiceHostBase class.

屬性

Authentication

取得服務驗證行為。Gets the service authentication behavior.

Authorization

取得裝載之服務的授權行為。Gets the authorization behavior for the service hosted.

BaseAddresses

取得裝載之服務使用的基底位址。Gets the base addresses used by the hosted service.

ChannelDispatchers

取得服務主機使用的通道發送器集合。Gets the collection of channel dispatchers used by the service host.

CloseTimeout

取得或設定允許服務主機關閉的時間間隔。Gets or sets the interval of time allowed for the service host to close.

Credentials

取得裝載之服務的認證。Gets the credential for the service hosted.

DefaultCloseTimeout

取得允許服務主機關閉的預設時間間隔。Gets the default interval of time allowed for the service host to close.

DefaultOpenTimeout

取得允許服務主機開啟的預設時間間隔。Gets the default interval of time allowed for the service host to open.

Description

取得裝載之服務的描述。Gets the description of the service hosted.

Extensions

取得目前指定服務主機的延伸。Gets the extensions for the current specified service host.

ImplementedContracts

擷取由裝載之服務實作的合約。Retrieves the contracts implemented by the service hosted.

IsDisposed

取得值,這個值表示是否已經處置通訊物件。Gets a value that indicates whether the communication object has been disposed.

(繼承來源 CommunicationObject)
ManualFlowControlLimit

取得或設定由裝載之服務接收的訊息流量控制限制。Gets or sets the flow control limit for messages received by the service hosted.

OpenTimeout

取得或設定允許服務主機開啟的時間間隔。Gets or sets the interval of time allowed for the service host to open.

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)

方法

Abort()

導致通訊物件立即從目前的狀態轉換為關閉狀態。Causes a communication object to transition immediately from its current state into the closing state.

(繼承來源 CommunicationObject)
AddBaseAddress(Uri)

將基底位址新增至服務主機。Adds a base address to the service host.

AddDefaultEndpoints()

針對在具有預設繫結的服務主機上找到的各個合約,為所有的基底位址加入服務端點。Adds service endpoints for all base addresses in each contract found in the service host with the default binding.

AddServiceEndpoint(ServiceEndpoint)

將指定的服務端點加入至裝載的服務。Adds the specified service endpoint to the hosted service.

AddServiceEndpoint(String, Binding, String)

使用指定的合約、繫結和端點位址,將服務端點加入至裝載的服務。Adds a service endpoint to the hosted service with a specified contract, binding, and endpoint address.

AddServiceEndpoint(String, Binding, String, Uri)

使用指定的合約、繫結、端點位址,以及包含其接聽所在位址的 URI,將服務端點新增至裝載的服務。Adds a service endpoint to the hosted service with a specified contract, binding, endpoint address and URI that contains the address at which it listens.

AddServiceEndpoint(String, Binding, Uri)

使用指定的合約、繫結以及含有端點位址的 URI,將服務端點新增至裝載的服務。Adds a service endpoint to the hosted service with a specified contract, binding, and a URI that contains the endpoint address.

AddServiceEndpoint(String, Binding, Uri, Uri)

使用指定的合約、繫結以及含有端點與接聽位址的 URI,將服務端點新增至裝載的服務。Adds a service endpoint to the hosted service with the specified contract, binding, and URIs that contain the endpoint and listening addresses.

ApplyConfiguration()

從組態檔載入服務描述資訊,並將其套用至正在建構的執行階段。Loads the service description information from the configuration file and applies it to the runtime being constructed.

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)
CreateDescription(IDictionary<String,ContractDescription>)

在衍生類別中實作時,建立裝載之服務的描述。When implemented in a derived class, creates the description of the hosted service.

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)
IncrementManualFlowControlLimit(Int32)

使用指定的增量,增加前往裝載之服務的訊息流量率限制。Increases the limit on the flow rate of messages to the hosted service by a specified increment.

InitializeDescription(UriSchemeKeyedCollection)

使用合約和服務描述建立並初始化服務主機。Creates and initializes the service host with the contract and service descriptions.

InitializeRuntime()

初始化服務主機的執行階段。Initializes the runtime for the service host.

LoadConfigurationSection(ServiceElement)

從裝載之服務的組態檔載入服務項目。Loads the service element from the configuration file of the hosted service.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnAbort()

中止服務。Aborts the service.

OnBeginClose(TimeSpan, AsyncCallback, Object)

開始服務主機關閉時所叫用的非同步作業。Begins an asynchronous operation invoked on the close of the service host.

OnBeginOpen(TimeSpan, AsyncCallback, Object)

開始服務主機開啟時所叫用的非同步作業。Begins an asynchronous operation invoked on the opening of the service host.

OnClose(TimeSpan)

關閉裝載的服務,包括其通道發送器以及相關執行個體內容和接聽程式。Closes down the hosted service, including their channel dispatchers and associated instance contexts and listeners.

OnClosed()

釋放服務主機使用的資源。Releases resources used by the service host.

OnClosing()

在將通訊物件轉換為關閉狀態期間會叫用。Invoked during the transition of a communication object into the closing state.

(繼承來源 CommunicationObject)
OnEndClose(IAsyncResult)

完成關閉服務主機時所叫用的非同步作業。Completes an asynchronous operation invoked on the closing of the service host.

OnEndOpen(IAsyncResult)

完成開啟服務主機時所叫用的非同步作業。Completes an asynchronous operation invoked on the opening of the service host.

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 channel dispatchers.

OnOpened()

取得裝載之服務的服務認證、服務驗證及授權行為。Gets the service credentials,service authentication and authorization behavior for the hosted service.

OnOpening()

在將通訊物件轉換至開啟狀態期間會叫用。Invoked during the transition of a communication object into the opening state.

(繼承來源 CommunicationObject)
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)
ReleasePerformanceCounters()

釋放裝載之服務的服務和通道發送器效能計數器。Releases the service and channel dispatcher performance counters for the hosted service.

SetEndpointAddress(ServiceEndpoint, String)

將指定之端點的端點位址設定為指定的位址。Sets the endpoint address of the specified endpoint to the specified address.

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)
UnknownMessageReceived

發生於收到未知訊息時。Occurs when an unknown message is received.

明確介面實作

IDisposable.Dispose()

關閉服務主機。Closes the service host.

適用於