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(  );
Trace.WriteLine(traceMessage);

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.

Get COM & .NET Component Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.