Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 86 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
86
Dung lượng
1,12 MB
Nội dung
Contents Overview 1 COM+ Context 2 The IObjectContext Interface 6 Lab 4.1 Using Context Object Services 15 Just In Time Activation 18 ManagingTransactions 25 Programming COM+ Transactions 38 Lab 4.2 ManagingTransactions 48 ManagingState 51 Using the Shared Property Manager 59 Lab 4.3 Storing State in the Middle Tier 69 Best Practices 74 Review 76 Module4:ManagingTransactionsandState 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, Intellisense, PowerPoint, and Visual Basic 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. Module4:ManagingTransactionsandState iii Instructor Notes This module describes transactionsand related concepts and issues. Students learn to activate and deactivate components by using Just In Time (JIT) Activation and As Soon As Possible (ASAP) deactivation. They will learn to use the Shared Property Manager (SPM) to manage state. This module also covers best programming practices to increase application scalability and efficiency. After completing this module, students will be able to: ! Use the context object to retrieve information about a COM+ component. ! Add transaction support for COM+ components by using the Component Services tool. ! Enable JIT Activation for COM+ components. ! Create COM+ components that support and manage distributed transactions. ! Use the SPM to manage the application data referred to as state. ! Describe some of the best practices when managingtransactionsand state. In the first two labs, students will learn how to use the context object services to retrieve information about the context object and to manage transactions. In the third lab, students will use the Shared Property Manager to store state in the middle tier of the Purchase Order Online application. 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_04.ppt ! Module4:ManagingTransactionsandState ! Lab 4.1: Using Context Object Services ! Lab 4.2: ManagingTransactions ! Lab 4.3: Storing State in the Middle Tier 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. Presentation: 135 Minutes Lab: 90 Minutes iv Module4:ManagingTransactionsandStateModule Strategy Use the following strategy to present this module: ! COM+ Context Discuss the concept of an object’s context and how each COM+ object is created with an associated context. For components that do not use COM+ services, the context is largely ignored. However, for components running inside COM+ applications, contexts are the foundation on which COM+ services are provided. The context object information is exposed through several interfaces on the ObjectContext object. ! Just In Time Activation Discuss how JIT Activation is used to create an object when a COM+ component is instantiated. JIT Activation helps make COM+ solutions scalable by activating objects as they are required and by preventing idle objects from consuming valuable resources on the server. ! ManagingTransactions Discuss how transactions can be managed automatically by using COM+ services. Describe the purpose of transactions in an enterprise solution. Transactions are required to maintain data integrity and to synchronize updates to data in multiple data sources. ! Programming COM+ Transactions Explain that sometimes developers need to control transactions programmatically even though they can be managed declaratively through COM+ services. The main reason for programming COM+ transactions is to gain a greater degree of control over the process. For example, a component may enforce a business rule that causes a transaction to abort if certain conditions arise, such as a balance transfer exceeding a specified maximum amount. Discuss the context object interfaces and how they are used to program COM+ transactions. ! ManagingState Discuss that state refers to the data used within the business processes of an application. When building enterprise solutions, managingstate is a major design concern. Explain that components can be stateful or stateless, and discuss the implications on component design resulting from state. ! Using the Shared Property Manager Discuss how the SPM is a resource dispenser provided by COM+ to store transient shared data in a COM+ application. The SPM allows you to retain global data between component activations and share it among all component instances in the COM+ application process. ! Best Practices Summarize all the best practices taught in the module. Module4:ManagingTransactionsandState v Demonstration This section provides demonstration procedures that will not fit in the margin notes or that are not appropriate for the student notes. Using the ObjectControl Interface ! Explain the demonstration scenario • The demonstration scenario is based on the Northwind database. A COM+ application is used to discontinue products that are no longer available. The client application calls a component named Traders, which invokes its DiscontinueProduct method. The Traders component calls a component named EventLog, invoking its LogEvent method to record the name of the user discontinuing the product. Next, Traders calls a component named Product, which invokes its Discontinue method to update the Products table. If an error occurs, Traders calls a component named ErrorLog, invoking its LogError method to record the error information and the ActivityID of the COM+ activity. ! Run the test client 1. Run the NwindClient.exe client application from the <install folder>\Democode\Mod04\NorthwindClient folder. 2. Enter a number below 100 and click Discontinue. A message will confirm the discontinued product. 3. Enter a number over 200 and click Discontinue. An error message will be displayed. ! Examine the database 1. Start Enterprise Manager from the Microsoft SQL Server 7.0 program group. 2. Expand the nodes in the Tree pane to view the tables in the Northwind database. 3. View the contents of the EventLog table and note the name of the user recorded there by the Traders component. 4. View the contents of the ErrorLog table and note the ActivityID recorded there by the Traders component. ! Examine the component code 1. Open Northwind.vbp in the <install folder>\Democode\Mod04\NorthwindComponent folder. 2. Display the code for the Traders class and examine the DiscontinueProduct method. 3. Under the comment Declare Object Context variable, add the following variable declaration: Dim objCtx As COMSVCSLib.ObjectContext vi Module4:ManagingTransactionsandState 4. Under the comment Get a reference to the Object Context, add the following code: Set objCtx = COMSVCSLib.GetObjectContext 5. Point out the following line of code: strUser = "Graeme" 'Get name from ISecurityProperty 6. Change this line to the following: strUser = objCtx.Security.GetOriginalCallerName 7. Point out the following line of code in the error handler: strActivity = "{00000000-0000-0000-0000-000000000000}" 8. Change the code to: strActivity = objCtx.ContextInfo.GetActivityID 9. Save and recompile the component (you may need to shut down the Northwind COM+ application) and close Microsoft Visual Basic. ! Run the test client 1. Run the NwindClient.exe client application from the <install folder>\Democode\Mod04\NorthwindClient folder. 2. Enter a number below 100 and click Discontinue. A message will confirm the discontinued product. 3. Enter a number over 200 and click Discontinue. An error message will be displayed. ! Examine the database 1. Start Enterprise Manager from the SQL Server 7.0 program group. 2. Expand the nodes in the Tree pane to view the tables in the Northwind database. 3. View the contents of the EventLog table and note the name of the user recorded there by the Traders component. 4. View the contents of the ErrorLog table and note the ActivityID recorded there by the Traders component. ManagingTransactions ! To prepare for the demonstration ! Ensure the SetupDemos.cmd file has been executed as previously described. ! Run the test client 1. Run the NwindClient.exe client application from the <install folder>\Democode\Mod04\NorthwindClient folder. 2. Enter a number below 100 and click Discontinue. A message will confirm the discontinued product. 3. Enter a number over 200 and click Discontinue. An error message will be displayed. Module4:ManagingTransactionsandState vii ! Examine the database 1. Start Enterprise Manager from the SQL Server 7.0 program group. 2. Expand the nodes in the Tree pane to view the tables in the Northwind database. 3. View the contents of the EventLog table and note that events have been recorded for product updates that did not take place. Explain that the reason is that the business process is not atomic. ! Configure the COM+ components 1. Open the Component Services administration tool and display the properties of the components in the Northwind application. 2. Point out that the Traders component does not support transactions. Change its Transaction support attribute to Required. 3. Ask students to explain why the Transaction support property of the ErrorLog component is set to Requires New. 4. Shut down the Northwind application and close Component Services. ! Add code to commit or abort the transaction 1. Open Northwind.vbp in the <install folder>\Democode\Mod04\NorthwindComponent folder. 2. Display the code for the Traders class and examine the DiscontinueProduct method. 3. Add the following line of code under the comment Commit Transaction: objCtx.SetComplete 4. Add the following line of code under the comment Abort Transaction: objCtx.SetAbort 5. Save and recompile the project and close Visual Basic. ! Run the test client 1. Run the NwindClient.exe client application from the <install folder>\Democode\Mod04\NorthwindClient folder. 2. Enter a number below 100 and click Discontinue. A message will confirm the discontinued product. 3. Enter a number over 200 and click Discontinue. An error message will be displayed. ! Examine the database 1. Start Enterprise Manager from the SQL Server 7.0 program group. 2. Expand the nodes in the Tree pane to view the tables in the Northwind database. 3. View the contents of the EventLog table and note that events have not been recorded for product updates that did not take place. Explain that the reason is that the business process is not an atomic transaction. Module4:ManagingTransactionsandState 1 # ## # Overview ! COM+ Context ! Lab 4.1: Using Context Object Services ! Just In Time(JIT) Activation ! ManagingTransactions ! Programming COM+ Transactions ! Lab 4.2: Using Context to Manage Transactions ! ManagingState ! Using the Shared Property Manager ! Lab 4.3: Storing State in the Middle Tier ! Best Practices and Review In this module, you will learn how to use the context object to obtain security, transactional, and other information about COM+ components. You will learn how COM+ uses Just In Time (JIT) Activation to free system resources and improve performance. You will also learn how to manage distributed transactions both declaratively and programmatically. Finally, you will learn how to manage state by using the Shared Property Manager (SPM). Objectives After completing this module, you will be able to: ! Use the context object to retrieve information about a COM+ component. ! Add transaction support for COM+ components by using the Component Services tool. ! Enable JIT Activation for COM+ components. ! Create COM+ components that support and manage distributed transactions. ! Use the Shared Property Manager to manage the application data referred to as state. 2 Module4:ManagingTransactionsandState # ## # COM+ Context ! Overview of the Context Object ! Interfaces for the Context Object ! The IObjectContext Interface ! The IContextInfo Inteface ! The ISecurityProperty Interface ! The IContextState Interface ! Demonstration: The Context Object Every COM object is created with an associated context. For components that do not use COM+ services, the context is largely ignored. However, for components running inside COM+ applications, contexts are the foundation on which COM+ services are provided. The context object information is exposed through an object named ObjectContext. This section includes the following topics: ! Overview of the Context Object ! Interfaces for the Context Object ! The IContextInfo Interface ! The ISecurityProperty Interface ! The IContextState Interface ! Demonstration: The Context Object [...]... COMSVCSLib.IContextState Set objCxSt = GetObjectContext Module4:ManagingTransactionsandState Alternatively, you can access the IContextState interface through an already instantiated ObjectContext object, as shown in the following code Dim Dim Set Set objCx As COMSVCSLib.ObjectContext objCxSt As COMSVCSLib.IContextState objCx = GetObjectContext objCxSt = objCx 13 14 Module4:ManagingTransactionsand State. .. objCtx = Nothing End Sub Module4:ManagingTransactionsandState 25 # ManagingTransactions ! Introduction to Transaction Processing ! Distributed Transactions ! ManagingTransactions Declaratively ! Processing Transactions ! Determining Transaction Outcome ! Observing Transaction Behavior In an enterprise solution, transactions are often required to maintain data integrity and to synchronize updates... section, you will learn how transactions can be managed automatically by using COM+ services This section includes the following topics: ! Introduction to Transaction Processing ! Distributed Transactions ! ManagingTransactions Declaratively ! Processing Transactions ! Determining Transaction Outcome ! Observing Transaction Behavior 26 Module4:ManagingTransactionsandState Introduction to Transaction... access security methods and properties through the ISecurityCallContext interface This interface provides greater functionality than the ISecurityProperty interface and should usually be used to manage programmatic security For more information about the ISecurityCallContext interface, see Module 8: Making Applications Secure 11 12 Module4:ManagingTransactionsandState The IContextState Interface ! Methods... context The following illustration shows the relationship between the client, the COM+ components, and the associated shared context 3 4 Module4:ManagingTransactionsandState Inherited Context Some components, such as those that require transactions, are not compatible with the component that called them and a new context must be created When a new context is required, COM+ allows certain properties... set the Done flag by writing code to call the SetComplete and SetAbort methods of the ObjectContext object, or the SetDeactivateOnReturn method of the IContextState interface This code will tell COM+ that the object has completed all requested processing and can be deactivated when the method call returns Module 4:ManagingTransactionsandState 21 You can also configure methods so that they automatically... IContextState that provides methods for controlling object lifetime andtransactions This interface can be obtained by calling GetObjectContext or by assigning an IContextState variable to an instantiated ObjectContext object Each of these interfaces is discussed in more detail later in this section 6 Module4:ManagingTransactionsandState The IObjectContext Interface Methods of the IObjectContext Interface... Delivery Tip The step-by-step instructions for this demonstration are in the instructor notes for this module In this demonstration, you will be shown how to access the IObjectContext, ISecurityProperty, and IContextInfo interfaces by using the ObjectContext object Module 4:ManagingTransactionsandState Lab 4.1 Using Context Object Services Slide Objective To introduce the lab Lead-in In this lab,... exercise provides practice working with the concepts and techniques covered in this module: ! Exercise 1: Using the Security Property In this exercise, you will use the Security property of the context object to identify the user who is calling the component Estimated time to complete this lab: 30 minutes 15 16 Module4:ManagingTransactionsandState Exercise 1: Using the Security Property In this... Programs, Microsoft SQL Server 7.0, and then click Query Analyzer 6 Log on to the (local) SQL Server and use Windows NT Authentication 7 In the Query window, select PurchaseOrderSystem from the DB dropdown list Module 4:ManagingTransactionsandState 8 Enter the following SQL query in the Query window, and then click Execute Query SELECT * FROM orderheader 9 Note that the last order placed has a RaisedBy . see Module 8: Making Applications Secure. Note 12 Module 4: Managing Transactions and State The IContextState Interface ! Methods of the IContextState. components, and the associated shared context. 4 Module 4: Managing Transactions and State Inherited Context Some components, such as those that require transactions,