oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

.NET Serviced Components
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

Configuring Serviced Components

You can use various .NET attributes to configure your serviced components to take advantage of COM+ component services. The rest of this chapter demonstrates this service by service, according to the order in which the COM+ services are presented in this book.

Application Activation Type

To specify the COM+ application's activation type, you can use the ApplicationActivation assembly attributes. You can request that the application be a library or a server application:

[assembly: ApplicationActivation(ActivationOption.Server)]


[assembly: ApplicationActivation(ActivationOption.Library)]

If you do not provide the ApplicationActivation attribute, then .NET uses a library activation type by default. Note that this use differs from the COM+ default of creating a new application as a server application.

TIP:   The next release of Windows 2000, Windows XP (see Appendix B), allows a COM+ application to be activated as a system service, so I expect that ApplicationActivation will be extended to include the value of ActivationOption.Service.

Before I describe other serviced components attributes, you need to understand what attributes are. Every .NET attribute is actually a class, and the attribute class has a constructor (maybe even a few overloaded constructors) and, usually, a few properties you can set. The syntax for declaring an attribute is different from that of any other class. In C#, you specify the attribute type between square brackets [...]. You specify constructor parameters and the values of the properties you wish to set between parentheses (...).

In the case of the ApplicationActivation attribute, there are no properties and the constructor must accept an enum parameter of type ActivationOption, defined as:

enum ActivationOption{Server,Library}

There is no default constructor for the ApplicationActivation attribute.

The ApplicationActivation attribute is defined in the System.EnterpriseServices namespace. Your must add this namespace to your project references and reference that namespace in your assembly information file:

using System.EnterpriseServices;

The rest of this chapter assumes that you have added these references and will not mention them again.

TIP:   A client assembly that creates a serviced component or uses any of its base class ServicedComponent methods must add a reference to System.EnterpriseServices to its project. Other clients, which only use the interfaces provided by your serviced components, need not add the reference.

The Description Attribute

Related Reading

COM and .NET Component ServicesCOM and .NET Component Services
By Juval Lwy
Table of Contents
Sample Chapter
Full Description

The Description attribute allows you to add text to the description field on the General Properties tab of an application, component, interface, or method. Example 10-2 shows how to apply the Description attribute at the assembly, class, interface, and method levels. After registration, the assembly-level description string becomes the content of the hosting COM+ application's description field; the class description string becomes the content of the COM+ component description field. The interface and method descriptions are mapped to the corresponding interface and method in the Component Services Explorer.

Example 10-2: Applying the Description attribute at the assembly, class, interface, and method levels

[assembly: Description("My Serviced Components Application")]
[Description("IMyInterface description")]
public interface IMyInterface
   [Description("MyMethod description")]   
   void MyMethod(  );
[Description("My Serviced Component description")]
public class MyComponent :ServicedComponent,IMyInterface
   public void MyMethod(  ){}

Accessing the COM+ Context

To access the COM+ context object's interfaces and properties, .NET provides you with the helper class ContextUtil. All context object interfaces (including the legacy MTS interfaces) are implemented as public static methods and public static properties of the ContextUtil class. Because the methods and properties are static, you do not have to instantiate a ContextUtil object--you should just call the methods. For example, if you want to trace the current COM+ context ID (its GUID) to the Output window, use the ContextId static property of ContextUtil:

using System.Diagnostics;//For the Trace class  
Guid contextID = ContextUtil.ContextId;
String traceMessage = "Context ID is " + contextID.ToString(  );

ContextUtil has also properties used for JITA deactivation, transaction voting, obtaining the transactions and activity IDs, and obtaining the current transaction object. You will see examples for how to use these ContextUtil properties later in this chapter.

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

Next Pagearrow