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)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Deactivate()

当对象即将停用时由基础结构调用。 重写该方法以在使用实时 (JIT) 编译代码或对象池时向对象添加自定义终止代码。

Dispose()

释放由 ServicedComponent 使用的所有资源。

Dispose(Boolean)

释放由 ServicedComponent 占用的非托管资源,还可以另外再释放托管资源。

DisposeObject(ServicedComponent)

完成对象并移除关联的 COM+ 引用。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时。

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()
已过时。

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

IRemoteDispatch.RemoteDispatchAutoDone(String)

此 API 支持产品基础结构,不能在代码中直接使用。

确保在 COM+ 上下文中,ServicedComponent 类对象的 done 位在远程方法调用后设置为 true

IRemoteDispatch.RemoteDispatchNotAutoDone(String)

不确保在 COM+ 上下文中,ServicedComponent 类对象的 done 位在远程方法调用后设置为 true

IServicedComponentInfo.GetComponentInfo(Int32, String[])

获取关于 ServicedComponent 类实例的某些信息。

适用于