Architecture of Component Services

Team-Fly    

Developing XML Web Services and Server Components with Visual C#™ .NET and the .NET Framework, Exam Cram™ 2 (Exam 70-320)
By Amit Kalani, Priti Kalani

Table of Contents
Chapter 8.  Component Services


In this section, you'll learn about the basic components of the COM+ architecture. You'll learn how a COM+ application is organized, how COM+ provides the component services, and how the .NET Framework interacts with COM+.

Serviced Components

Any class that uses enterprise services must derive from the System.EnterpriseServices.ServicedComponent class. Such a class is also called a serviced component.

graphics/note_icon.gif

COM can instantiate the .NET classes only with public default constructors. COM cannot create an object and pass parameters for object creation at the same time.


The ServicedComponent class has methods but no properties or events. The important methods of this class are listed in Table 8.1. All these methods are protected except the DisposeObject() method, which is a public static method. You can override the protected methods in a class inherited from the ServicedComponent class.

Table 8.1. Important Methods of the ServicedComponent Class

Method

Description

Activate()

Can be used to perform startup operations. It is called when an object is created or allocated from a pool.

CanBePooled()

Indicates whether the object should be pooled. It is called when an object is to be moved to the pool.

Construct()

Provides access to the construction string of the serviced component. It is called after the serviced component object is created that is, after the constructor is executed.

Deactivate()

Can be used to perform cleanup operations. It is called when an object is about to be deactivated that is, destroyed or moved to a pool.

DisposeObject()

Finalizes the resources used by the serviced component and removes the associated COM+ reference.

Declarative Programming Model

Unlike the conventional procedural model, the programming model for enterprise services is mostly declarative. In Visual C# .NET, you use attributes for this purpose. For example, to create a component that supports transactions, you add the Transaction attribute, as shown here:

 [Transaction(TransactionOption.Required)] public class MySampleSC : ServicedComponent {    ... } 

graphics/note_icon.gif

Attributes are represented by classes whose names end in the word Attribute. For example, the Transaction attribute is implemented by the TransactionAttribute class. In your code, you are allowed to leave off the "Attribute" suffix, and I recommend that you do so to increase your code's readability.


Important attributes of the System.EnterpriseServices namespace and their descriptions are listed in Table 8.2.

Table 8.2. Important Attributes of the System.EnterpriseServices Namespace

Attribute

Scope

Description

ApplicationAccessControl

Assembly

Enables you to configure the security of an application hosting the serviced component.

ApplicationActivation

Assembly

Specifies whether the serviced components are activated in the creator's process (ActivationOption.Library, the default value) or in the system's process (ActivationOption. Server).

ApplicationID

Assembly

Specifies the GUID of the COM+ application.

ApplicationName

Assembly

Specifies the name of the COM+ application.

ApplicationQueuing

Assembly

Enables queuing support for the COM+ application.

AutoComplete

Method

Indicates whether the method should automatically notify the COM+ context about its success or failure when it completes.

ComponentAccessControl

Class

Enables security checking when the serviced component is accessed.

COMTIIntrinsics

Class

Allows the context properties to be passed from the COM transaction integrator (COMTI) to the COM+ context.

ConstructionEnabled

Class

Allows the component to pass a construction string to enable object construction.

Description

Assembly Class Method Interface

Specifies the description of the assembly, class, method, or interface.

EventClass

Class

Indicates that a class can participate in loosely coupled events.

EventTrackingEnabled

Class

Enables event tracking on the component.

ExceptionClass

Class

Specifies the queuing exception class.

InterfaceQueuing

Class Interface

Enables queuing support on the specified interface or class.

JustInTimeActivation

Class

Indicates whether the serviced component supports just-in-time activation.

LoadBalancingSupported

Class

Indicates whether the serviced component supports load balancing.

MustRunInClientContext

Class

Indicates whether the serviced component must be created in the creator's context.

ObjectPooling

Class

Indicates whether the serviced component will be created in an object pool, and configures the size of the pool.

PrivateComponent

Class

Specifies that a serviced component should not be visible and should not be activated outside its containing COM+ application.

SecureMethod

Assembly Class Method

Indicates that the methods of the serviced component should be called through an interface so that the security is applied.

SecurityRole

Assembly Class Interface

Indicates the security role that will have access to the serviced component.

Synchronization

Class

Specifies the synchronization support offered to the serviced component. It controls how multiple threads can execute the methods of the serviced component simultaneously.

Transaction

Class

Specifies the transaction support required by the serviced component.

COM+ Applications

A COM+ application is a group of serviced components that perform related functions. Each of these components further consists of interfaces and methods. A COM+ application is the primary unit of administration and deployment for the serviced components.

A COM+ application is always stored in a DLL file. A DLL file cannot run on its own, so a COM+ application is always configured to run in one of the following two ways:

  • Server application In a server application, a COM+ application runs in its own process. To enable this, COM+ provides a surrogate process (dllhost.exe) that hosts the DLL file for the COM+ application.

  • Library application In a library application, the COM+ application runs in the process of the client that creates it. To enable this, the components in a library application are always loaded into the process of the creator.

graphics/alert_icon.gif

When choosing whether to run a COM+ application as a server application or a library application, you should look at both security and functional requirements. Server applications tend to offer lower performance but higher security than library applications. Library applications also do not support some COM+ services, including object pooling and queued components.


COM+ Catalog

The COM+ catalog stores the information about the COM+ applications. Each COM+ application and serviced component is uniquely identified in the COM+ catalog by a globally unique identifier (GUID).

The other important information stored in the COM+ catalog for a serviced component is its runtime requirements. For example, if a component requires a transaction, this information is stored in the COM+ catalog. Later, when the component is activated, COM+ services use the catalog to determine the runtime requirements of components.

You can access and update the catalog in an integrated way by using the Component Services administrative tool. This tool is available in the Administrative Tools section of the Windows Control Panel.

Serviced Component Activation

Activation of a serviced component can be summarized in the following steps:

  1. When a client component creates a new instance of a serviced component, the .NET enterprise services uses the COM-based CoCreateInstance() API to request COM+ to instantiate the serviced component.

  2. COM+ uses the GUID of the component to retrieve the runtime information from the COM+ catalog. COM+ then checks to see whether the client component is running in an environment that is compatible with the runtime requirements of the serviced component.

  3. If the runtime requirements of the serviced component match with those of the client program, the new object is created in the same context (runtime environment) as the client program. A reference to the newly created object is returned to the client component so that the client component can make direct calls on the newly created object.

  4. If the runtime requirements of the serviced component are not compatible with those of the client program, COM+ creates a new context that matches the client's runtime requirements and creates the serviced component in that environment. The COM+ component services then create a proxy and return the proxy to the client component.

  5. The client program uses the proxy to communicate with the serviced component.

A context is a set of runtime properties that define the execution environment for a serviced component. A context is created during the activation process for a serviced component based on how the serviced component is configured. Objects with the same runtime requirements share a context, whereas those with incompatible runtime requirements must reside in different contexts.

An object can access its context-specific properties by using the ContextUtil class of the System.EnterpriseServices namespace. Important members of the ContextUtil class are listed in Table 8.3.

Table 8.3. Important Members of the ContextUtil Class

Member

Type

Description

DeactivateOnReturn

Property

Indicates whether the object should be deactivated when the object's method returns.

DisableCommit()

Method

Indicates that the COM+ context votes to abort the current transaction. This method does not deactivate the object when the object's method returns.

EnableCommit()

Method

Indicates that the COM+ context votes to commit the current transaction. This method does not deactivate the object when the object's method returns.

IsCallerInRole()

Method

Determines whether the caller is in a specified role.

IsInTransaction

Property

Indicates whether the current COM+ context is transactional.

IsSecurityEnabled

Property

Indicates whether the current COM+ context has role-based security enabled.

MyTransactionVote

Property

Specifies the COM+ context transaction vote abort or commit.

Transaction

Property

Represents the current COM+ transaction object.

SetAbort()

Method

Indicates that the COM+ context votes to abort the current transaction. This method also deactivates the object when the object's method returns.

SetComplete()

Method

Indicates that the COM+ context votes to commit the current transaction. This method also deactivates the object when the object's method returns.


    Team-Fly    
    Top


    MCAD Developing XML Web Services and Server Components with Visual C#. NET and the. NET Framework Exam Cram 2 (Exam Cram 70-320)
    Managing Globally with Information Technology
    ISBN: 789728974
    EAN: 2147483647
    Year: 2002
    Pages: 179

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net