ServicedComponent 類別

定義

表示所有使用 COM+ 服務之類別的基底類別。

public ref class ServicedComponent abstract : ContextBoundObject, IDisposable, System::EnterpriseServices::IRemoteDispatch, System::EnterpriseServices::IServicedComponentInfo
[System.Serializable]
public abstract class ServicedComponent : ContextBoundObject, IDisposable, System.EnterpriseServices.IRemoteDispatch, System.EnterpriseServices.IServicedComponentInfo
[<System.Serializable>]
type ServicedComponent = class
    inherit ContextBoundObject
    interface IRemoteDispatch
    interface IDisposable
    interface IServicedComponentInfo
Public MustInherit Class ServicedComponent
Inherits ContextBoundObject
Implements IDisposable, IRemoteDispatch, IServicedComponentInfo
繼承
衍生
屬性
實作

範例

下列程式碼範例示範如何將類別公開為已設定的 COM 元件。


[assembly:ApplicationName("Calculator")];
[assembly:ApplicationActivation(ActivationOption::Library)];
[assembly:System::Reflection::AssemblyKeyFile("Calculator.snk")];
public ref class Calculator: public ServicedComponent
{
public:
   int Add( int x, int y )
   {
      return (x + y);
   }

};
using System;
using System.EnterpriseServices;

[assembly: ApplicationName("Calculator")]
[assembly: ApplicationActivation(ActivationOption.Library)]
[assembly: System.Reflection.AssemblyKeyFile("Calculator.snk")]
public class Calculator : ServicedComponent
{
    public int Add (int x, int y)
    {
        return(x+y);
    }
}

若要將此類別部署為已設定的 COM 元件,您必須產生強金鑰、將類別編譯為程式庫,以及註冊程式庫。 下列三個命令會完成這三個步驟。

sn -k Calculator.snk  
csc /t:library Calculator.cs  
regsvcs Calculator.dll  

備註

在某些情況下,衍生自 ServicedComponent COM+ 應用程式中執行的類別可能會停止回應。 此問題是由活動死結所造成。 由於元件參考的非同步清除,活動可以在多執行緒應用程式上死結。 若要解決此問題,當您完成使用衍生自 ServicedComponent 的物件時,請呼叫 Dispose 方法。

注意

用戶端程式代碼必須在服務元件上呼叫 Dispose ,以確保正常運作。

建構函式

ServicedComponent()

初始化 ServicedComponent 類別的新執行個體。

方法

Activate()

從集區建立或配置物件時由基礎結構所呼叫。 覆寫這個方法來加入自訂初始化程式碼至物件。

CanBePooled()

這個方法在物件放回集區內之前為基礎結構所呼叫。 覆寫這個方法來表決物件是否要放回到集區內。

Construct(String)

剛好在傳入建構函式字串並呼叫建構函式之後由基礎結構所呼叫。 覆寫這個方法來利用建構字串值。

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Deactivate()

物件即將停用時由基礎結構所呼叫。 在使用 Just-In-Time (JIT) 編譯的程式碼或物件共用時,可覆寫這個方法來加入自訂最終處理程式碼至物件。

Dispose()

釋放 ServicedComponent 所使用的所有資源。

Dispose(Boolean)

釋放 ServicedComponent 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

DisposeObject(ServicedComponent)

結束物件並移除相關 COM+ 參考。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IRemoteDispatch.RemoteDispatchAutoDone(String)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

確保在 COM+ 內容中,ServicedComponent 類別物件的 done 位元會在 Remote Method Invocation 之後設為 true

IRemoteDispatch.RemoteDispatchNotAutoDone(String)

不能確保在 COM+ 內容中,ServicedComponent 類別物件的 done 位元會在 Remote Method Invocation 之後設為 true

IServicedComponentInfo.GetComponentInfo(Int32, String[])

取得 ServicedComponent 類別執行個體的某些資訊。

適用於