Szerkesztés

Megosztás a következőn keresztül:


ServicedComponent Class

Definition

Represents the base class of all classes using COM+ services.

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
Inheritance
Derived
Attributes
Implements

Examples

The following code example demonstrates how to expose a class as a configured COM component.


[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);
    }
}

To deploy this class as a configured COM component, you must generate a strong key, compile the class as a library, and register the library. These three steps are accomplished by the following three commands.

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

Remarks

Under certain conditions, a class that is derived from ServicedComponent that runs in a COM+ application may stop responding. This problem is caused by an Activity deadlock. Activities can deadlock on multithreaded applications because of an asynchronous cleanup of component references. To work around this problem, call the Dispose method when you complete work with objects derived from ServicedComponent.

Note

Client code must call Dispose on serviced components to ensure proper operation.

Constructors

ServicedComponent()

Initializes a new instance of the ServicedComponent class.

Methods

Activate()

Called by the infrastructure when the object is created or allocated from a pool. Override this method to add custom initialization code to objects.

CanBePooled()

This method is called by the infrastructure before the object is put back into the pool. Override this method to vote on whether the object is put back into the pool.

Construct(String)

Called by the infrastructure just after the constructor is called, passing in the constructor string. Override this method to make use of the construction string value.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Deactivate()

Called by the infrastructure when the object is about to be deactivated. Override this method to add custom finalization code to objects when just-in-time (JIT) compiled code or object pooling is used.

Dispose()

Releases all resources used by the ServicedComponent.

Dispose(Boolean)

Releases the unmanaged resources used by the ServicedComponent and optionally releases the managed resources.

DisposeObject(ServicedComponent)

Finalizes the object and removes the associated COM+ reference.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IRemoteDispatch.RemoteDispatchAutoDone(String)

This API supports the product infrastructure and is not intended to be used directly from your code.

Ensures that, in the COM+ context, the ServicedComponent class object's done bit is set to true after a remote method invocation.

IRemoteDispatch.RemoteDispatchNotAutoDone(String)

Does not ensure that, in the COM+ context, the ServicedComponent class object's done bit is set to true after a remote method invocation.

IServicedComponentInfo.GetComponentInfo(Int32, String[])

Obtains certain information about the ServicedComponent class instance.

Applies to