Serviced Component Overview

A serviced component is a class that is authored in a CLS-compliant language and that derives directly or indirectly from the System.EnterpriseServices.ServicedComponent class. Classes configured in this way can be hosted in a COM+ application and can use COM+ services by way of the EnterpriseServices namespace. For a list of supported services, see Summary of Available COM+ Services.

COM+ services, such as automatic transactions or Queued Components, can be configured declaratively. You apply service-related attributes at design time and create instances of classes that use those services. You configure some services by calling methods on service-related classes or interfaces. Some services can flow from one object to another. For example, an object configured to require a transaction can extend that transaction to a second object if the second object also supports or requires transactions.

The COM+ catalog holds the configuration information that you apply to a class implementation. At run time, based on the attributes you apply to your code, COM+ creates a context service layer. The following illustration shows an automatic transaction that flows between two managed objects hosted by COM+.

COM+ application hosting serviced components

7c05y13x.comserviceoverview(en-us,VS.71).gif

Services can also flow between COM+ and .NET Framework objects. Each environment controls the implementation and execution of its native code; COM+ always provides the object context.

To create a serviced component

  1. Define a class that derives directly or indirectly from the ServicedComponent class. For example, the following code ensures that the Account class is hosted by a COM+ application.

    Imports System.EnterpriseServices
    Public Class Account 
    Inherits ServicedComponent
    Shared Sub Main()
    End Sub
    End Class
    [C#]
    using System.EnterpriseServices;
    public class Account : ServicedComponent
    {
       static void Main()
       {}
    }
    
  2. The following code applies service attributes to the assembly, class, or method.

    Imports System.EnterpriseServices
    <Transaction(TransactionOption.Required)> Public Class Account 
    Inherits ServicedComponent
       <AutoComplete()> Shared Sub Main()
       End Sub
    End Class
    [C#]
    using System.EnterpriseServices;
    [Transaction(TransactionOption.Required)]
    public class Account : ServicedComponent
    {
       [AutoComplete]
       static void Main() 
    {}
    }
    

    Note   In .NET Framework version 1.1, the COM+ security configuration is enabled by default if the ApplicationAccessControlAttribute attribute is not present in the assembly. This is a change in behavior from .NET Framework version 1.0.

  3. You can compile the example as follows:

    Makefile.bat

    vbc /t:exe /r:System.EnterpriseServices.dll Demo.vb
    [C#]
    csc /t:exe /r:System.EnterpriseServices.dll Demo.cs
    
  4. Deploy the serviced component application by registering its assembly dynamically or manually. For more information, see Dynamic registration and Manual registration.

After a serviced component is registered, clients can create instances of the component the way they create instances of any other component. For a complete example, see Serviced Component Example.

Note   On Windows 2000 platforms, COM+ always loads the most recent version of the common language runtime for the component you're creating. This means that on a computer with both .NET Framework version 1.0 and .NET Framework version 1.1 installed, .NET Framework version 1.1 is always loaded. As a workaround, you can create a COM+ dllhost.exe.configuration file that enables you to "lock" all applications to a specific version of .NET Framework. On Windows XP and Windows Server 2003 platforms, the Application Root Directory setting can be used to point COM+ to an appropriate directory for its configuration file.

See Also

Writing Serviced Components | Applying Attributes to Configure Services | Registering Serviced Components | Serviced Component Example | Summary of Available COM+ Services | System.EnterpriseServices.ServicedComponent