Contents
Overview 1
From COM to COM+ 2
COM+ Architecture 16
Administering COM+ Applications 23
Lab 3.1 Building a COM+ Application 40
Debugging a COM+ Component 48
Deploying a COM+ Application 57
Lab 3.2: Debugging COM+ Components 72
Best Practices 75
Review 77
Module 3: Introduction
to COM+
Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
to represent any real individual, company, product, or event, unless otherwise noted. Complying
with all applicable copyright laws is the responsibility of the user. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation. If, however, your only
means of access is electronic, permission to print one copy is hereby granted.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
2000 Microsoft Corporation. All rights reserved.
Microsoft, BackOffice, MS-DOS, Windows, Windows NT, Active Directory, ActiveX, Microsoft
SQL Server, MSDN, PowerPoint, Visual Basic, Visual C++, and Visual Studio are either
registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.
The names of companies, products, people, characters, and/or data mentioned herein are fictitious
and are in no way intended to represent any real individual, company, product, or event, unless
otherwise noted.
Other product and company names mentioned herein may be the trademarks of their respective
owners.
Module 3: Introduction to COM+ iii
Instructor Notes
This module describes the origins and advantages of COM+. It introduces the
COM+ architecture and explains how to create, debug, and deploy COM+
components.
After completing this module, students will be able to:
!
Describe how the Component Object Model (COM) and Microsoft
Transaction Server (MTS) have evolved to become COM+.
!
List and describe the COM+ services.
!
Create and add a component to a COM+ application.
!
Debug a COM+ component.
!
Deploy a COM+ application.
In the labs, students will learn to create, debug, and deploy COM+ applications.
Materials and Preparation
This section provides you with the required materials and preparation tasks that
are needed to teach this module.
Required Materials
To teach this module, you need the following materials:
!
Microsoft PowerPoint file 1907A_03.ppt
!
Module 3: Introduction to COM+
!
Lab 3.1: Building a COM+ Application
!
Lab 3.2: Debugging COM+ Components
Preparation Tasks
To prepare for this module, you should:
!
Read all of the materials for this module.
!
Complete the labs.
!
Read the instructor notes and the margin notes for the module.
!
Review Appendix A: Understanding COM Fundamentals and Appendix B:
Working with COM Interfaces.
Presentation:
145 minutes
Lab:
100 minutes
iv Module 3: Introduction to COM+
Module Strategy
Use the following strategy to present this module:
!
From COM to COM+
Discuss the evolution of the Component Object Model. Explain how classic
COM provides a programming model and supporting run-time library,
which together assist in the creation of component-based software systems.
Also explain how MTS changed the programming model by introducing the
idea of attribute-based programming, a key concept embraced by COM+.
This model allowed developers to tap into MTS-provided infrastructure
services simply by establishing a set of attributes within the MTS catalog—
the information collectively known as the class’s configuration. Explain
how the key MTS services have been enhanced and extended by COM+.
!
COM+ Architecture
Describe the architecture of a COM+ application. Discuss the elements of
the COM+ environment, which consists of applications and components.
Discuss some of the supporting services and technologies that work with
COM+ to manage system resources and transactions.
!
Administering COM+ Applications
Show students how they can use the Component Services tool to manage
and administer existing COM+ applications and components. Explain that
the Component Services administration tool can also be used to create
COM+ applications, add components to applications, and view information
about COM+ components. Discuss the COM+ catalog, which acts as a data
store for COM+ applications and component configuration information.
Explain how the COM+ administration objects are used by the Component
Services tool to access the catalog. Explain how these Automation objects
are also available to scripted clients, which allows the development of
automated administrative utilities.
There is a practice on creating a COM+ application and adding a component
to the newly created application.
!
Debugging a COM+ Component
There are a number of issues that need to be addressed when using
Microsoft Visual Basic to debug a COM+ component. Explain how to
configure a Microsoft ActiveX DLL project for out-of-process debugging.
Discuss some of the issues and limitations that need to be addressed when
debugging COM+ components.
Demonstrate how to debug an ActiveX DLL component within a COM+
application. Refer to the demonstration notes presented in the next section.
!
Deploying a COM+ Application
Explain how to use the Component Services tool to export COM+
applications for deployment on other servers. Students should also know
how to export application proxies for client-side deployment. Finally,
discuss the Windows 2000 Class Store, an Active Directory container used
for distributed setup and on-demand component installation.
There is a practice on exporting and importing a COM+ application by
using the Component Services tool.
Module 3: Introduction to COM+ v
One recommendation (and best practice) is to install a separate .tlb file
with the component DLL in a COM+ application. This approach allows only
the type library (and not the entire component DLL) to be deployed for client-
side installation. While this technique worked well under MTS and should work
under COM+, the Component Services Export Wizard generates an error when
exporting an application proxy. This error only occurs if the type library is
installed in addition to a DLL containing an embedded copy of the type library.
The error displayed is as follows:
"Error occurred writing to the application file. Either the path cannot be
accessed or an existing file cannot be overwritten. Make sure you entered
the full path for the application file. The application was not exported."
Visual Basic DLLs always contain an embedded copy of the type library, even
if the Remote Server Files option has been selected to generate a separate type
library. This issue remains unresolved.
Demonstration
This section provides demonstration procedures that will not fit in the margin
notes or that are not appropriate for the student notes.
Debugging COM+ Components
The purpose of this demonstration is to demonstrate how to debug an ActiveX
DLL component within a COM+ application. The other objective is to illustrate
how COM+ interjects VB6Debug.dll into the COM+ application for the
duration of the debug session. This demonstration uses the sample BankApp
component DLL located in <install folder>\Democode\Mod3\Debugging.
!
Prepare for the demonstration
1. Create a COM+ server application called BankApp. Take all the default
options when creating this application.
2. Insert the BankApp component DLL into the application. This DLL
contains one class called CAccount, which represents a bank account.
3. Familiarize yourself with the BankApp component by loading the
BankApp.vbp project in Microsoft Visual Basic. Notice that the CAccount
class has three public routines: Deposit, Withdraw, and GetBalance.
4. Familiarize yourself with the TestHarness executable by loading the
TestHarness.vbp project in Visual Basic. The main form of the TestHarness
project displays three buttons, which call the three public routines of the
CAccount class.
Note
vi Module 3: Introduction to COM+
!
Perform the demonstration
1. Show students the BankApp application within the Component Services
tool.
2. Display the properties of the BankApp.CAccount class and illustrate the
current DLL file location prior to debugging.
3. Load the BankApp.vbp project into Visual Basic.
4. Set breakpoints within the Deposit, Withdraw, and GetBalance routines.
5. Demonstrate how to set the current debugging option to start the
TestHarness executable by using the Debugging tab of the Project
Properties dialog box. Select the Start program option and set the start
program to TestHarness.exe.
6. Run the BankApp project.
7. The TestHarness application will be launched.
8. Switch back to the component services tool, refresh the Components folder
within the BankApp application, and again view the BankApp.CAccount
class properties. Show students how the DLL for this class has now been set
to VB6Debug.dll.
9. Click the Deposit button on the test harness. The Visual Basic process will
halt at the breakpoint.
10. Use F8 to step over the code within the routine and then click the Run
button to return control to the test harness.
11. Click the remaining buttons on the test harness—Withdraw and
GetBalance—to which demonstrate how the breakpoints are hit in each
case.
12. Now end the debug session by pressing the End toolbar button within
Visual Basic.
13. Return to the Component Services tool, refresh the Components folder, and
view the properties of the BankApp.CAccount class. Demonstrate how the
original component DLL file has been reestablished within the application.
14. Stress that if the debug session ends abnormally, there is a danger of
VB6Debug.dll being left as the registered component within the application.
Module 3: Introduction to COM+ 1
#
##
#
Overview
!
From COM to COM+
!
COM+ Architecture
!
Administering COM+ Applications
!
Lab 3.1: Building a COM+ Application
!
Debugging a COM+ Component
!
Deploying a COM+ Application
!
Lab 3.2: Debugging COM+ Components
!
Best Practices
!
Review
In this module, you will learn about COM+ services and how to use these
services to support enterprise systems development. The Component Object
Model (COM) and Microsoft Transaction Server (MTS) have been integrated to
become COM+ in Microsoft Windows 2000. COM+ provides prefabricated
infrastructure to support the middle-tier functionality of an enterprise system.
This module focuses on key COM+ services and the architecture of a COM+
application. You will learn how to create, debug, and deploy a COM+
application.
For information about COM and COM interfaces, see Appendix A:
Understanding COM Fundamentals and Appendix B: Working with COM
Interfaces.
Objectives
After completing this module, you will be able to:
!
Describe how COM and MTS have evolved to become COM+.
!
List and describe the COM+ services.
!
Create and add a component to a COM+ application.
!
Debug a COM+ component.
!
Deploy a COM+ application.
Slide Objective
To provide an overview of
the module topics and
objectives.
Lead-in
In this module, you will learn
how to use COM+ queued
components and events to
provide message-based
asynchronous
communication.
2 Module 3: Introduction to COM+
#
##
# From COM to COM+
!
COM Programming Model
!
Using COM Interfaces
!
Implementing Interfaces
!
Microsoft Transaction Server
!
COM+ Programming Model
!
COM+ Services
In this section, you will learn about the evolution of COM. You will learn how
classic COM provides a programming model and supporting run-time library,
which together assist in the creation of component-based software systems.
You will learn how MTS enhanced the COM programming model by
introducing attribute-based programming. With attribute-based programming,
COM developers can administratively tap into a rich set of infrastructure-
related services provided by MTS. In Windows 2000, COM and MTS have
been consolidated to form COM+, the latest component programming model.
Finally, you will learn how to take advantage of COM+ services to build
distributed applications.
This section includes the following topics:
!
COM Programming Model
!
Using COM Interfaces
!
Implementing Interfaces
!
Microsoft Transaction Server
!
COM+ Programming Model
!
COM+ Services
Module 3: Introduction to COM+ 3
COM Programming Model
!
COM defines a programming model and provides a
supporting run-time library
$
To facilitate component-based development (CBD)
!
Components provide discrete units of functionality
$
Offering a service or services
!
Component-based applications are easier to adapt and
maintain
!
This course focuses on DLL-based components
$
EXE components can’t take advantage of COM+ services
COM defines a programming model and provides a supporting run-time library
that facilitates the development of software components. A component can be
thought of as a discrete unit of functionality offering a particular service or
services. In an insurance application, for example, a PremiumCalculator
component may provide a calculation service capable of generating insurance
premiums based on risk data. Another component might search for a customer’s
city and state based on the zip code entered.
The fundamental goal of COM is to enable applications to be constructed from
preassembled parts or components. Such applications are easier to maintain and
change than the so-called monolithic applications built prior to the component
era. Components provide these advantages because they can be replaced with
newer versions over time and with minimal impact on the rest of the system.
COM components also benefit from vendor independence, language
independence, and location transparency.
Developing COM+ applications in Visual Basic means that you do not have to
worry about many low-level details of COM. However, you should have a
fundamental working knowledge of basic COM concepts and terminology
before you start developing COM+ applications. For more information about
COM, see Appendix A: Understanding COM Fundamentals.
In this course, you will focus on DLL-based components because only
DLLs can take advantage of the benefits provided by COM+. Windows 2000
supports EXE-based components, but these components will not be able to
benefit from the many additional services and features provided by COM+.
Note
4 Module 3: Introduction to COM+
Using COM Interfaces
!
The Set statement is used to obtain references to
interfaces.
CTradingAccount
IAccount
ITrade
Dim objIAcc As Utils.IAccount
Dim objITrade As Utils.ITrade
Set objIAcc = New Utils.IAccount
‘ Use IAccount interface
‘ Query for ITrade interface
Set objITrade = objIAcc
‘ Use ITrade interface
‘ Release references
Set objIAcc = Nothing
Set objITrade = Nothing
IUnknown
_CTradingAccount
Interfaces are central to COM development because objects always interact
through a COM interface. The interface defines the behavior of the object and
specifies the precise syntax of the functions used to communicate with the
object. When programming in Visual Basic, it is not always apparent that
interfaces are being used when interacting with COM objects. Visual Basic
presents a COM object as an entity exposing a set of methods, properties, and
sometimes events. Under normal circumstances, a Visual Basic client will be
connected to the default interface exposed by the COM object.
When working in the COM+ environment, it is sometimes necessary to interact
with a COM object through several of its supported interfaces. For example, the
COM+ context object discussed in this module exposes a number of interfaces
providing transaction and security-related functionality.
Sometimes, it is necessary to develop a Visual Basic class module that
implements an externally defined COM interface specified in a type library. For
example, this technique is essential when developing COM+ event classes used
with the COM+ Event service. For more information about the COM+ Event
service, see Module 5: Queued Components and Events.
Default Interfaces
The Set statement is used in conjunction with New or CreateObject to obtain
an object’s initial interface. This interface is usually the object’s default
interface, although the exact interface returned depends on the type of the
variable being set. Consider an account object exposing IAccount and ITrade
interfaces. The following illustration shows the COM object together with the
client code required to navigate between the two supported interfaces.
The above illustration shows an interface called _CtradingAccount. This
interface is the object’s default interface generated by Visual Basic when a class
module is compiled. The name of this interface is derived from the name of the
class module. In this example, the default interface contains no public functions
because the object’s functionality is exposed solely by means of the IAccount
and ITrade interfaces.
Module 3: Introduction to COM+ 5
The first Set statement used with the New keyword results in a reference to an
interface of type IAccount. This reference is determined by the type of the
objIAcc variable. The second Set statement queries the object for the ITrade
interface. ITrade is requested because the objITrade variable is of type ITrade.
For a detailed insight into COM interfaces, refer to Appendix B: Working with
COM Interfaces. This appendix also discusses how to handle error conditions
(for example, when the object does not support the requested interface).
6 Module 3: Introduction to COM+
Implementing Interfaces
!
The Implements keyword is used to implement externally
described interfaces.
IAccount
Implements Utils.IAccount
Implements Utils.ITrade
'IAccount implementation
Private Sub IAccount_Deposit( ByVal dblAmount As Double )
‘Code statements
End Sub
Private Sub IAccount_Withdraw( ByVal dblAmount As Double )
‘Code statements
End Sub
Private Function IAccount_GetBalance( ) As Double
'Code statements
End Function
'ITrade implementation
Private Sub ITrade_Buy( ByVal lngQuantity As Long )
'Code statements
End Sub
Private Sub ITrade_Sell( ByVal lngQuantity As Long )
'Code statements
End Sub
IAccount
ITrade
Interface Definitions
within Type Libraries
ITrade
IUnknown
CTradingAccount Class Module
When working in the COM+ environment, it may be necessary to create a COM
class that implements one or more externally defined COM interfaces.
To create a COM object that implements externally defined interfaces, create a
class module and then specify the Implements keyword, followed by the
interface name for each interface to be implemented. You must first establish a
reference to the type library or libraries containing definitions of the externally
defined interfaces. The above illustration shows how a class module called
CTradingAccount would implement two externally defined interfaces called
IAccount and ITrade.
When implementing an interface, you must provide implementations for all of
the functions defined in the interface.
Some clients may want to use only the IAccount interface, while other clients
may use only the ITrade interface or both interfaces. Implementing multiple
and separate interfaces allows classes to be more versatile in what features they
expose and use. For more information about the Implements keyword, see
Appendix B: Working with COM Interfaces.
Module 3: Introduction to COM+ 7
Microsoft Transaction Server
!
Traditional Services
$
Object Request Broker
$
Surrogate Server Process
$
Transaction Processing Monitor
!
MTS Services
$
Concurrency Management
$
Resource Management
$
Transactions
$
Role-Based Security
!
Attribute-Based Programming
$
Allows components to be configured via a set of attributes
$
Provides services based on the component’s configuration
MTS was the first Microsoft product to provide the infrastructure for enterprise
solutions. The rationale for MTS was to allow the separation of an application’s
business logic, which varies greatly from one application to another, from the
enterprise infrastructure, which essentially remains constant.
MTS enhances the COM programming model. While the underlying mechanics
of COM do not change, MTS provides an extra wrapper layer that rests on top
of COM. MTS provides an environment for hosting regular DLL-based
components. These components, typically containing business logic, can then
inherit enterprise infrastructure (such as security and transaction services)
directly from MTS.
8 Module 3: Introduction to COM+
Traditional Services
MTS represents a new type of technology that combines the features of
traditional distributed object technology with traditional online transaction
processing (OLTP) to provide the following services.
Service Description
Object Request Broker When a call comes in to a server requesting an
object, the Object Request Broker (ORB) handles
the call, checks for availability, and, subject to
security restrictions, gives the caller an object.
Surrogate Server Process MTS components must be in-process components
so that all objects can be created within MTS-
managed server processes, referred to as MTS
packages. The MTS surrogate server process uses
the MTS Executive (a DLL) to provide the run-
time support required by component-based,
scalable application servers.
Transaction Processing Monitor A Transaction Processing Monitor (TPM) knows
nothing about objects, but it does know how to
optimize the use of system resources. It can also
create, execute, and manage transaction-
processing applications.
MTS Services
The key services provided by MTS have been carried forward and extended in
COM+. These services include the following.
Service Description
Concurrency management Provides services to handle the complex issues
associated with concurrency and brought about by many
users simultaneously accessing a component. This
service allows component developers to focus on writing
business logic.
Resource management Conserves resources, including memory, network, and
database connections.
Transactions Provides an all-or-nothing, simple model of managing
work.
Role-based security Allows you to administratively configure the security
requirements of your applications by defining roles
(collections of users) and restricting access to sensitive
areas based on role membership.
Attribute-Based Programming
MTS introduced the notion of attribute-based programming, a key concept
embraced by COM+. Attribute-based programming allows you to configure
components by means of a set of attributes. The attributes define the types of
MTS-provided services required at run time. Attributes are applied
administratively, often at system deployment time, by using a graphical
administrative tool called the MTS Explorer. Attributes are held within a data
store called the MTS Catalog.
Module 3: Introduction to COM+ 9
At run time, when MTS activates a component, it accesses the catalog to find
out what additional services the component requires. For example, components
that have a transactional attribute set would need to be automatically enlisted in
a transaction.
MTS provides this additional functionality through the use of a helper object
called the context wrapper. The MTS run time intercepts regular component
activation requests and inserts a wrapper object between the client and the
object. A pointer to the context wrapper is returned to the client. The client
cannot differentiate between the wrapper and the real object.
With the wrapper in place, MTS can intercept every method call made by the
client. This interception allows MTS to provide any additional functionality that
may be required based on the component’s configuration. The context wrapper
also facilitates Just In Time (JIT) Activation. Objects can be activated and
deactivated under the control of the context wrapper and transparently to the
client.
10 Module 3: Introduction to COM+
COM+ Programming Model
!
Context
$
COM+ uses contexts to group together objects with the
same run-time requirements.
$
A Context Object exists for each context.
!
Interception
Context A
Context B
Proxy to
Object A
Object
B
Object
A
Act iva tor
Interception services provided
by proxies
Proxy to
Object B
Context C
Process boundary
In Microsoft Windows 2000, COM+ represents the integration of COM and
MTS. In addition, COM+ has extended the base COM model in a number of
areas, has extended the services introduced by MTS, and has added some
completely new services.
Before looking at the services provided by COM+, it is worth considering some
of the fundamental techniques used by COM+ to understand how the service-
based environment works.
Context
COM+ uses a logical abstraction referred to as a context to group objects
together that share the same run-time requirements. This concept is similar to
the apartment abstraction, which existed in Windows NT 4 and still exists
under Windows 2000. However, while the apartment exists to group together
objects with similar concurrency constraints, contexts group together objects
based on their general run-time requirements. The run-time requirements of a
class are determined by the set of configuration attributes defined for the class
in the COM+ Catalog. A component’s attributes determine the type of services
it requires. These services are provided by COM+ at run time.
The collective set of attributes describing the services that a component requires
is referred to as the component’s configuration. There are two classes of
components.
Component class Description
Configured components These components have been installed into the COM+
environment and have an associated attribute set.
Nonconfigured components These components run outside the COM+ environment
and include out-of-process servers.
Module 3: Introduction to COM+ 11
In Windows 2000, processes are partitioned into contexts. Because different
classes can be configured with different requirements, a process often contains
more than one context to separate incompatible objects from one another. All
cross-context communication occurs by means of a proxy-stub pair. The proxy
is responsible for switching the run-time environment from the caller’s
configuration to the target object’s configuration. The types of operation the
proxy may need to perform include transaction enlistment, lock acquisition, and
JIT Activation, among others. This process is called interception.
Each context in a process has a unique COM object, referred to as the context
object, which represents the context. This object is a similar but extended
version of the context object found in MTS. In Visual Basic, you gain access to
the context object by using the GetObjectContext function. You can then use
this object to interact with the services provided by COM+, such as transaction
management and JIT Activation. For more information about managing
transactions, see Module 4: Managing Transactions and State.
Interception
COM+ provides services to configured components by using a technique
referred to as interception. The concept of interception originated with MTS.
However, while MTS used a separate context wrapper object, COM+ fuses
together the functionality of MTS and COM. As a result, COM+ provides
interception directly through proxy objects.
To further understand the concept of interception, it is useful to look at the steps
that are performed during object activation under COM+. COM+ object
activation is an extended form of the object activation process in previous
versions of COM.
1. When an object is activated in Visual Basic by using New or CreateObject,
CoCreateInstance (the underlying API in the COM library) is called.
Under COM+, CoCreateInstance checks to see if the activator (that is, the
code that called New or CreateObject) is running in a context that is
compatible with the class’s configuration.
2. If the activator’s context is compatible, no interception is needed; as a
result, a direct reference to the object is returned. If the activator’s context is
not compatible, CoCreateInstance creates the object in a new context
based on the object’s configuration and returns a proxy to the activator.
3. When the activator makes regular COM calls against the proxy, the proxy
performs the required services (interception) before and after each method
invocation to ensure that the run-time environment is compatible with the
class’s requirements during method execution.
12 Module 3: Introduction to COM+
COM+ Services
!
Concurrency Management with Activities
$
Allows you to write components from the point of view of
a single user
Many of the services provided by COM+ are enhanced versions of MTS
services. COM+ also introduces a number of new services, all of which are
designed to make it easier to create enterprise applications.
Concurrency Management with Activities
When a distributed application provides services to multiple users, it can
receive simultaneous calls from clients. It can also have its business logic
running in more than one process on more than one computer. The
synchronization issues involved with managing multiple threads on multiple
computers are complex to program. Using a simple concurrency model to
develop distributed applications enables you to focus on writing the business
logic for your application rather than the synchronization code.
COM+ provides this simple concurrency model through activities. An activity
is the path of execution that occurs from the time a client creates a COM+
object until the client releases that object. During the activity, the client makes
calls to the COM+ object. To service those calls, the COM+ object may create
additional objects that are part of the same activity. The activity ensures that all
COM+ objects created on behalf of the original client do not run in parallel.
You can think of an activity as a single logical thread of execution. Using
activities enables you to write your COM+ components from the point of view
of a single user.
The following illustration shows the activity associated with a transfer
component making use of debit and credit components. COM+ attempts to
ensure that concurrent execution never occurs within a single activity.
Module 3: Introduction to COM+ 13
COM+ Services (continued)
!
Resource Management
$
Just In Time (JIT) Activation
$
Thread pooling
$
Object pooling
$
Connection pooling
!
Transactions
!
Queued Components
$
Asynchronous message-based communication
!
Events
$
Loosely coupled publisher / subscriber architecture
!
Security
$
Based on roles
Resource Management
As an application scales to a larger number of clients, objects in the application
must share resources such as network connections, database connections,
memory, and disk space, and they must use them only when necessary. COM+
provides a number of resource management features to improve scalability,
including Just in TIme (JIT) Activation, thread pooling, object pooling, and
database connection pooling.
!
Just In Time Activation
COM+ helps conserve server memory by keeping an instance of an object
alive only when a client is calling the object. This practice is known as JIT
Activation, and it allows the server to handle more clients than is possible
when the object remains active.
When a client calls a method on an object, COM+ activates the object by
creating it and allowing the client call to proceed. When the call returns and
the object finishes its work, COM+ deactivates the object by removing it
from memory. Later, when the client calls the object again, COM+
reactivates the object. From the client point of view, the object has always
been there and the object's reference has always been available.
!
Thread Pooling
As requests are received from clients, COM+ automatically assigns threads
to components from a preallocated pool. When a component finishes
executing, COM+ reclaims the thread. Reclaiming the thread reduces the
overhead of thread creation and deletion, and results in improved
performance.
!
Object Pooling
Object pooling allows you to configure a class to have instances of it cached
in a pool, ready to be used by any client that requests the class. This feature
can result in performance benefits because objects retrieved from the pool
are already initialized. COM+ allows you to configure upper and lower
limits for controlling the number of instances that may exist within the pool.
14 Module 3: Introduction to COM+
Visual Basic 6 components are unable to benefit from the object-
pooling feature because of threading model restrictions. The neutral
threading model required for object pooling is not currently supported by
Visual Basic.
!
Connection Pooling
COM+ also allows the use of resource dispensers, which can pool resources
such as database connections for more efficient use. For example, the
ODBC 3.0 Driver Manager is an ODBC resource dispenser. When an
ODBC database connection is released, the ODBC resource dispenser
returns the connection to a pool rather than releasing it immediately. If
another COM+ object requests the same connection, the connection will be
assigned from the pool, thereby saving unnecessary network trips to recreate
the connection.
For more information about COM+ resource management features, see Module
4: Managing Transactions and State.
Transactions
Work done in a distributed multiuser application can involve changes to
database tables and even nondatabase entities such as message queues.
Frequently, more than one object in an activity is initiating changes. Because
the work in any single object can fail, the application must be able to handle
situations in which some objects fail, but others succeed. Work cannot be left in
an inconsistent state in which some of the work is done, but other parts are not.
Transactions provide an all-or-nothing simple model of managing work. Either
all the objects succeed and all the work is committed, or one or more of the
objects fail and none of the work is committed. Based on the outcome, any
database tables or files affected by the work will either all be changed or none
will be changed at all (that is, they will not be left in an inconsistent state).
The programming required to manage transactions across multiple databases
and nondatabase entities is difficult to implement in an application. COM+
automatically provides this transaction management service by creating
transactions for components when they are activated. COM+ also automatically
handles cleanup and rollback of a failed transaction. When you use COM+, you
do not have to write any explicit transactional code in your components.
For more information about COM+ resource management features, see Module
4: Managing Transactions and State.
Queued Components
COM+ provides an asynchronous communications mechanism that allows
COM clients to make calls on a COM object when the object’s server computer
is not reachable on the network (for example, during disconnected operation).
The asynchronous style of communications employed by queued components is
based on messaging. When applications want to communicate with one another,
they send messages. If the target application is unavailable or unreachable,
messages are stored in holding areas or queues. You can think of queued
components as e-mail for applications. This mechanism makes it much easier to
write distributed applications because neither client nor server needs to care
about the other's lifetime.
Note
Module 3: Introduction to COM+ 15
A client application creates and interacts with a queued component in much the
same way as it would with any other component. The lack of change to the
COM programming model from the client and server’s perspective is one of the
key strengths of queued components.
With queued components, calls are recorded by a system utility, transmitted to
the server through asynchronous protocols, and played back by another system
utility into the server-side COM object when the server computer and server
process become available.
For more information using queued components, see Module 5: Queued
Components and Events.
Events
The COM+ Event service provides a flexible way for information publishing
applications to be connected to subscriber applications. A publisher is any
program that provides information updates, such as changes in stock prices or
interest rates. A subscriber is any program that wants to receive these
notifications.
For more information about COM+ events, see Module 5: Queued Components
and Events.
Security
Security is a key issue for enterprise applications because these applications
need to make sure that only authorized users are allowed to perform important
operations. Writing security code by using the raw Windows NT security
mechanism or the security APIs provided by DCOM is complex and time
consuming.
Using the COM+ security mechanism allows you to specify your application’s
security requirements administratively without writing any code. In situations
too complex for the administrative mechanism to handle, COM+ also provides
a simple programmatic interface.
COM+ provides security by allowing you to define roles. A role defines which
users (Windows NT user accounts and groups) are allowed to invoke interfaces
on a class. You map each role to specific classes, interfaces on those classes, or
even individual methods. Then you add Windows NT users and groups to their
appropriate roles. COM+ ensures that those Windows NT users and groups can
only access the classes and interfaces to which their roles are mapped. You do
not have to write any special code in your components to handle role-based
security.
Roles map well to real-world scenarios. For example, in a banking system, roles
may include cashiers, supervisors, and managers. You can restrict access to
sensitive areas of functionality within your application to the appropriate users
based on their roles.
For more information about COM+ security, see Module 8: Making
Applications Secure.
16 Module 3: Introduction to COM+
#
##
# COM+ Architecture
!
COM+ Applications
!
COM+ Components
!
Supporting Services
In this section, you will learn about the architecture of a COM+ application.
You will learn about the COM+ environment, which consists of applications
and components. You will also learn about some of the supporting services and
technologies that work with COM+ to manage system resources and
transactions.
This section includes the following topics:
!
COM+ Applications
!
COM+ Components
!
Supporting Services
Module 3: Introduction to COM+ 17
COM+ Applications
!
A COM+ application can be described as
$
A group of classes that perform related tasks.
$
A surrogate server process for hosting objects.
$
A trust boundary that enables you to control security for a group of
classes.
$
A unit of administration and deployment.
!
Separate server processes provide
$
Security context for each process.
$
Fault Isolation.
!
Types of COM+ Application
$
COM+ supports library applications in addition to server applications
$
Library applications run in client’s process address space.
A COM+ application consists of a collection of COM classes that are contained
within in-process components (DLLs). These classes generally contain business
logic. A COM+ application also contains the type libraries associated with its
classes. The application allows the classes to be administered and deployed as a
single unit and also provides a host process for objects at run time. A COM+
application could be described as any one of the following:
!
A group of classes that perform related tasks
!
A surrogate server process for hosting objects
!
A trust boundary that enables you to control security for a group of classes
!
A unit of administration and deployment
The terms class and component are often used interchangeably. The
Component Services administration tool views an application as consisting of a
set of components. Strictly speaking, a COM+ application contains classes from
one or more components (DLLs). Usually, a single component and all its
contained classes are installed in a single COM+ application. However, it is
possible to install individual classes from a single component into different
COM+ applications.
Separate Server Processes
Each active COM+ application normally runs as a distinct server process. The
server process is provided by COM+ and is in effect a surrogate process used to
host business components. The surrogate process used by COM+ is dllhost.exe.
Note
18 Module 3: Introduction to COM+
There are a number of benefits to using separate processes, including:
!
Security context for each process.
COM+ will perform security checks whenever a method is called from
outside an application. However, COM+ will not check security when one
component calls another inside the same application. The security
requirements of your system need to be considered when deciding in which
application various components should be placed.
!
Fault isolation.
Applications also define fault isolation boundaries. If a component in one
application fails, it can potentially result in the termination of the server
process in which it resides. It will not, however, affect components in other
applications because they are running in separate server processes. Fault
isolation is another factor to consider when determining in which
applications to put your components.
Resource pooling is on a per-process basis. By grouping components that
share expensive resources such as database connections in the same application,
you can improve the scalability of your application.
The following illustration shows the architecture of the Purchase Order
application that is used in the lab scenario.
Ti
p
Module 3: Introduction to COM+ 19
Types of COM+ Applications
It is possible to run COM+ applications in the address space of the client
process. To support this feature, COM+ defines two types of application.
Type Description
Server applications A server application is a COM+ application that runs in its
own process, as shown in the preceding illustration. A
separate copy of the COM+ surrogate process, dllhost.exe, is
used for each server application. A server application can
support all COM+ services.
Library applications Library applications are activated in the creator’s process. As
a result, it is not possible to directly control process-level
security. Library applications are affected by the security
enforced by the hosting process. For library applications, role
checking can only occur at the component level. Also, if a
component in a library application fails, it can easily cause
the creator’s process to terminate.
Library applications do not directly support access from
client processes on other computers (remote access) or
queued components. The main benefit of a library application
stems from the performance improvement brought about by
hosting the application in the client's process address space.
Library applications are also useful for utility components
that are used by other COM+ server applications.