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+ 应用程序中运行的派生类可能会停止响应。 此问题是由活动死锁引起的。 由于组件引用的异步清理,多线程应用程序上的活动可能会死锁。 若要解决此问题,请在处理派生自Dispose的对象时调用ServicedComponent该方法。

注释

客户端代码必须调用 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 类实例的某些信息。

适用于