1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Module 3: Introduction to COM+ pdf

84 520 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Introduction to COM+
Trường học Microsoft Corporation
Chuyên ngành Computer Science / Software Engineering
Thể loại Lecture Notes
Năm xuất bản 2000
Định dạng
Số trang 84
Dung lượng 1,49 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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.. Explain

Trang 1

Contents

Overview 1

Administering COM+ Applications 23

Lab 3.1 Building a COM+ Application 40

Deploying a COM+ Application 57

Lab 3.2: Debugging COM+ Components 72

Review 77

Module 3: Introduction

to COM+

Trang 2

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

Trang 3

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

Trang 4

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

Trang 5

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

Trang 6

! 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

Trang 7

# 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

In this module, you will learn

how to use COM+ queued

components and events to

provide message-based

asynchronous

communication

Trang 8

# From COM to COM+

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

Trang 9

COM Programming Model

supporting run-time library

maintain

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

Trang 10

Using COM Interfaces

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

Trang 11

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)

Trang 12

'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 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

Trang 13

Microsoft Transaction Server

! Traditional Services

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

Trang 14

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, the Object Request Broker (ORB) handles the call, checks for availability, and, subject to security restrictions, gives the caller an object

so that all objects can be created within 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

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

associated with concurrency and brought about by many users simultaneously accessing a component This service allows component developers to focus on writing business logic

database connections

work

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

Trang 15

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

Trang 16

COM+ Programming Model

same run-time requirements.

Context A Context B

Proxy to Object A

Object

B

Object

A Activator

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 based environment works

service-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

environment and have an associated attribute set

and include out-of-process servers

Trang 17

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

Trang 18

COM+ Services

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

Trang 19

COM+ Services (continued)

! 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

Trang 20

Visual Basic 6 components are unable to benefit from the pooling feature because of threading model restrictions The neutral threading model required for object pooling is not currently supported by Visual Basic

object-! 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

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

Note

Trang 21

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

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

Trang 23

COM+ Applications

! A COM+ application can be described as

classes

! Separate server processes provide

! Types of COM+ Application

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

Trang 24

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

Tip

Trang 25

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

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

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

Trang 26

COM+ Components

automatically Self registration/type library support

A COM+ application provides business services to clients As you have seen, a COM+ application is implemented as a collection of COM DLLs, with each DLL implementing different business services in the application The components are registered for use in the COM+ run-time environment, usually

by using the Component Services administration tool Such components are often referred to as COM+ components, and objects created from them are often called COM+ objects

The expression "configured component" is also used to refer to a COM component running in the COM+ environment This term is used because the component has an associated set of configuration attributes These attributes are stored in the COM+ catalog and are used by COM+ at run time

A client accesses a COM+ application by creating objects from the components and calling methods on those objects Object creation is performed in the

standard way, usually by using CreateObject or New The objects created by

the client may in turn create additional objects to complete the client's request

To use a component with COM+, it must be a COM DLL Components that are implemented as executable (.exe) files cannot run in the COM+ run-time environment Other requirements, such as self-registration and type library support, are met automatically when you create the component with Visual Basic

Note

Trang 27

Supporting Services

! Resource Managers

transactions

! Resource Dispensers

! Microsoft Distributed Transaction Coordinator

COM+ uses several system resources that are not integral parts of the COM+ environment to provide important resource and data management capabilities to COM+ components With the exception of the Shared Property Manager, COM+ uses all the following services automatically on your component's behalf

Resource Managers

A resource manager is a system service that manages durable data Resource managers ensure that data will not be lost or corrupted in the event of a system failure Examples of resource managers include the categories in the following table:

Category Description

versions 6.5 and 7.0 and Oracle versions 7.3.3 and 8.0

Queue Server

protocol or the X/Open XA protocol

COM+ automatically works with resource managers on your component's behalf For example, if your component is configured to require a transaction and it subsequently performs database updates against a resource manager such

as Microsoft SQL Server, COM+ will create and manage the transaction in the SQL Server database automatically You do not need to write any explicit transactional code in your components

COM+ supports resource managers that implement either the OLE Transactions protocol or the X/Open XA protocol The MTS Software Development Kit (SDK) in the Platform SDK provides a toolkit for developing resource managers suitable for use in the COM+ environment

Trang 28

Resource Dispensers

A resource dispenser is a service that manages nondurable, shared-state data on behalf of the components within a process Resource dispensers are similar to resource managers, but resource dispensers do not guarantee durability They are useful for managing shared state data that does not need the overhead of being protected from a system failure COM+ uses several resource dispensers, including the following:

! Shared Property Manager

! ODBC resource dispenser

! OLE DB resource dispenser For more information about resource dispensers, see the “Tool Developer’s Guide” in the Component Services section of the Platform SDK

Shared Property Manager

The Shared Property Manager provides synchronized access to defined, process-wide properties (or variables) You can use it for a variety of tasks, such as maintaining a Web page hit counter, caching static data, or providing smart caching to avoid database hotspots For more information about the Shared Property Manager, see Using the Shared Property Manager in Module 4: Managing Transactions and State

application-ODBC Resource Dispenser

The ODBC resource dispenser can be used to manage pools of database connections for COM+ components The resource dispenser automatically reclaims and reuses database connections This feature reduces the memory and network connections that the database connections consume on the COM+ server and increases scalability You must be using version 3.0 or later of the ODBC Driver Manager to benefit from ODBC connection pooling

You can configure ODBC connection pooling with ODBC 3.5 or later by

using the Data Sources (ODBC) administration tool, located on the

Programs->Administrative Tools menu in Windows 2000

OLE DB Resource Dispenser

ActiveX Data Objects (ADO) and the underlying services of OLE DB can be used to manage pools of connections and other connection-related resources OLE DB refers to this use as session or resource pooling If you use ADO, your database connections are pooled automatically by OLE DB session pooling

Microsoft Distributed Transaction Coordinator

Microsoft Distributed Transaction Coordinator (DTC) is a system service that coordinates transactions that span multiple resource managers Work can be committed as one transaction even if the transaction spans multiple resource managers on separate computers The DTC is an integral part of Windows

2000 For more information about distributed transactions, see Distributed Transactions in Module 4: Managing Transactions and State

Note

Trang 29

# Administering COM+ Applications

In this section, you will learn how to manage and administer COM+

applications and components You will learn how to use the Component Services administration tool to create COM+ applications and add components

to applications You will then learn about the COM+ catalog, which acts as a data store for COM+ applications and component configuration information Finally, you will learn about the COM+ administration objects that are used to access the COM+ catalog You will learn how to use COM+ administration objects from scripted languages such as Microsoft Visual Basic Scripting Edition so that you can develop administrative utilities

! Component Services Tool

! Setting Properties

! Practice: Creating a COM+ Application

! The COM+ Catalog

! COM+ Administration Objects

! Automating Application Creation

Trang 30

Component Services Tool

allowing you to:

transaction, queuing, and security.

The Component Services administration tool runs as a Microsoft Management Console (MMC) snap-in, giving it the same look and feel as other Windows

2000 administration tools The Component Services tool allows you to view the system and application event logs, monitor and control system services, and administer COM+ applications Using the Component Services tool, you can:

! Create an application

! Add and delete components from an application

! Set application and component properties such as transaction, queuing, and security

! Start and stop applications

! Deploy applications

! Install and maintain applications

! Monitor transactions

Trang 31

The following illustration shows the user interface for the Component Services tool

You can use the Component Services tool to manage and administer COM+ applications locally (located on My Computer) and on remote servers

! To add other computers to the tree view

1 Select and right-click the Computers folder, point to New, and select

Computer

2 Specify a computer name or browse to locate the required computer

Component Services Tool Views

The Component Services tool provides several views, such as List and Property views, so that you can select the information that you want to display in the right pane of the tool’s window You can change the Component Services view

from the View menu

Trang 32

To display all the properties for items in the selected folder, click Property on the View menu The following table shows what properties are displayed for

each folder type

Folder Properties

applications on each computer)

Security (enforce access checks), Impersonation (level), Account (under which application runs), Activation

(server or library), Shutdown (minutes until idle shutdown), Run Always, Proxy (server application or

application proxy)

Security (enforce component-level access checks), Synchronization (type required), Threading Model

To display the status of computers, COM+ applications, or components, click

Status on the View menu The following table shows what status properties are

displayed for each folder type

Folder Properties

(ms)

Trang 33

Setting Properties

! Application properties include

Setting Application Properties

You can set application properties for a COM+ application, such as how the application is accessed, how security is enabled, and whether the application should be reachable by Microsoft Message Queuing messages

To force a COM+ application process to shut down, right-click the

application and choose Shutdown You may need to do this if you have

changed component or application properties that won't be reflected until the application process is restarted

Tip

Trang 34

! To set properties for an application

• In the Component Services tool, right-click the name of the application and

select Properties The following illustration shows an example of the

Properties dialog box for a COM+ application

The following table describes some of the application properties and where you can set them

Tab Property Description General Name Displays the name of the application

General Description Displays a user-defined description of the

application

Security Authorization When roles have been defined, this property

allows COM+ to check the caller’s role membership on each call to the application

Security Security Level Determines whether access checks are performed

at the process (application) level or at the component level

Identity Account Determines the account under which this process

(application) will run This account can be that of the user who is currently logged on (the interactive user) or a specific account

Trang 35

Tab Property Description Activation Activation Type Determines how components in applications are

activated Server applications run as dedicated server processes, while library applications run in the same process address space as the client

Queuing Queued This option allows components within the

application to be reached by means of MSMQ messages For further details, see Module 5: Queued Components and Events

For more information about COM+ application properties, search for

"Configuring COM+ Applications" in the MSDN™ Library

Trang 36

Setting Class Properties

After you add a component to a COM+ application, you can set the properties for each class in the component The properties determine how the class participates in transactions, whether COM+ checks the security credentials of any client that calls the class, and the level of synchronization support required

! To set the properties of a class

• To set the properties of a class, right-click the name of the class in the

Component Services tool and select Properties The following illustration shows an example of the Properties dialog box for a component class

Trang 37

The following table describes the class properties and where you can set them

Tab Property Description General Description Displays general information about the class

description, CLSID, DLL file location, and application GUID

Transactions Transaction support Determines how a class supports transactions

Security Authorization Enables COM+ to perform access checks at

the component, interface, and method levels

Security Roles Lists the roles that have been explicitly

defined for the application You can explicitly grant access permission to the class for members of specific roles For further information, refer to Module 8: Making Applications Secure

Activation Enable object

pooling

When pooling is enabled, objects will be recycled and reused Note that Visual Basic 6 components do not support object pooling because of threading model restrictions

Activation Enable object

construction

Allows a construction string to be passed to the object when it is created This feature requires that the object implement the

Activation Must be activated

For more information about queued components, see Working with Queued Components in Module 5: Queued Components and Events

Trang 38

Placing Components in Applications

COM+ allows you to split individual classes from a single component across two or more COM+ applications However, an individual class can only reside

in a single application on a single computer You should remember this restriction when organizing your components and classes into applications For example, if you have a general-purpose component that will be used by many COM+ applications, you should put this component and others like it into a single COM+ application (such as Utilities) This application can then be installed as a unit where needed

You can use the Component Services tool to relocate an individual class within

a given component from one application to another

! To relocate a class

• Select and right-click the class within the application's Components folder

and select Move

Trang 39

Practice: Creating a COM+ Application

In this practice, you will learn how to create the skeleton code for a COM+ application by using the COM+ Application Install Wizard Then you will learn how to add components to the application you have created

! Create a COM+ application

1 Start the Component Services tool

On the Start menu, point to Programs, then point to Administrative

Tools, and select Component Services

2 In the left pane of the Component Services tool, expand Component Services and the Computers folder and then double-click the name of the computer in which you want to create a new COM+ application

3 Select and then right-click the COM+ Applications folder, point to New, and select Application

4 In the COM Application Install Wizard, click Next

5 Click the Create an empty application icon

You can install prebuilt applications to add an existing application that is created with the application export function For more information about deployment, see Deploying a COM+ Application in this module

6 Enter BankApp as the name for the new application, set the activation type

to Server Application, and click Next

7 Set the application identity to Interactive user - the current logged on

user

The application identity determines the account under which the application

runs You can specify Interactive User, which sets the user identity to the

user currently logged on to the Windows 2000 server Alternatively, to

specify a particular user, you can select the This user option and specify an

account name and password For more information about application identities, see Module 8: Making Applications Secure

8 Click Next and then click Finish to create the application

Trang 40

After you create a new COM+ application, you can add components that implement business services

! Add a component to a COM+ application

1 In the Component Services tool, expand the BankApp application within the COM+ Applications folder to display the Components folder

2 Select and then right-click the Components folder, point to New, and select

Component

3 In the COM Component Install Wizard, click Next

4 Click the Install New Component(s) icon

5 In the Select files to install dialog box, navigate to the <install

folder>\Practices\Mod03\BankApp folder Select BankApp.dll and then

click Open

You will see a dialog box that displays class information pertaining to the classes located in the selected component

6 Click Next and then Finish to complete the addition of the component

7 Expand the Components folder within the BankApp application Select and

then right-click the new component and select Properties Investigate the

default properties associated with the new component

Note You can also add components to the Components folder of a COM+

application by dragging DLLs that contain the COM classes you want from the Windows Explorer to the application

Ngày đăng: 11/12/2013, 14:15

TỪ KHÓA LIÊN QUAN