This topic has not yet been rated - Rate this topic

ServicedComponent Class

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

Namespace:  System.EnterpriseServices
Assembly:  System.EnterpriseServices (in System.EnterpriseServices.dll)
[SerializableAttribute]
public abstract class ServicedComponent : ContextBoundObject, 
	IRemoteDispatch, IDisposable, IServicedComponentInfo

The ServicedComponent type exposes the following members.

  Name Description
Public method ServicedComponent Initializes a new instance of the ServicedComponent class.
Top
  Name Description
Protected method 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.
Protected method 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.
Protected method Construct 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.
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Protected method 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.
Public method Dispose() Releases all resources used by the ServicedComponent.
Protected method Dispose(Boolean) Releases the unmanaged resources used by the ServicedComponent and optionally releases the managed resources.
Public method Static member DisposeObject Finalizes the object and removes the associated COM+ reference.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Explicit interface implemetation Private method IRemoteDispatch.RemoteDispatchAutoDone Ensures that, in the COM+ context, the ServicedComponent class object's done bit is set to true after a remote method invocation
Explicit interface implemetation Private method IRemoteDispatch.RemoteDispatchNotAutoDone Does not ensure that, in the COM+ context, the ServicedComponent class object's done bit is set to true after a remote method invocation.
Explicit interface implemetation Private method IServicedComponentInfo.GetComponentInfo Obtains information about the ServicedComponent class instance.
Top

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. For more information, see http://support.microsoft.com/default.aspx?scid=kb;en-us;327443.

Note Note

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

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


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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
... not CLS-compliant?!?
My apologies if this is not the place to comment about it.

I recently upgraded a VB.NET project consisting of Serviced Components, a "business layer" of sorts for our main system, to VS2010. Everything works OK. I, however, am puzzled to find out that the compiler seems to think ServicedComponent is a non CLS-compliant class, and all of the classes that inherit from it are, in turn, non CLS-compliant. Is that expected? Should the documentation be updated signaling this... or is this not true at all, and I have something wrong with my copy of VS2010?


[tfl - 24 06 10] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&