00 973x FM 8/28/00 2:22 PM Page i Scot Hillier’s COM+ Programming with Visual Basic® Scot Hillier 800 East 96th St.,Indianapolis,Indiana,46240 USA 00 973x FM 8/28/00 2:22 PM Page ii Copyright ©2000 by Sams Publishing ASSOCIATEPUBLISHER Bradley L. Jones FIRSTEDITION All rights reserved. No part of this book shall be reproduced,stored in a ACQUISITIONSEDITOR retrieval system,or transmitted by any means,electronic,mechanical,photo- Sharon Cox copying,recording,or otherwise,without written permission from the pub- DEVELOPMENTEDITOR lisher. No patent liability is assumed with respect to the use of the information Susan Shaw Dunn contained herein. Although every precaution has been taken in the preparation of this book,the publisher and author assume no responsibility for errors or MANAGINGEDITOR omissions. Neither is any liability assumed for damages resulting from the use Charlotte Clapp of the information contained herein. For information,address Sams Publishing, PROJECTEDITOR A division of Macmillan Computer Publishing,201 W. 103rd St.,Indianapolis, Paul Schneider IN 46290. International Standard Book Number:0-672-31973-X COPYEDITOR Rhonda Tinch-Mize Library of Congress Catalog Card Number:00-102598 INDEXER Printed in the United States of America Chris Barrick First Printing:September 2000 PROOFREADER 03 02 01 00 4 3 2 1 Kimberly Campanello Interpretation of the printing code:the rightmost double-digit number is the TECHNICALEDITOR year of the book’s printing; the rightmost single-digit,the number of the Rick Anderson book’s printing. For example,a printing code of 98-1 shows that the first print- ing of the book occurred in 1998. TEAMCOORDINATOR Meggo Barthlow Composed in Function Condensed,AGaramond and MCPdigital by Macmillan Computer Publishing SOFTWARESPECIALISTS William Eland,Jr. Trademarks Dan Scherf All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to INTERIORDESIGNER the accuracy of this information. Use of a term in this book should not be Anne Jones regarded as affecting the validity of any trademark or service mark. COVERDESIGNER Aren Howell Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as LAYOUTTECHNICIANS possible,but no warranty or fitness is implied. The information provided is on Ayanna Lacey an “as is”basis. The author and the publisher shall have neither liability nor Heather Hiatt Miller responsibility to any person or entity with respect to any loss or damages aris- Stacey Richwine-DeRome ing from the information contained in this book or from the use of the CD or programs accompanying it. 00 973x FM 8/28/00 2:22 PM Page iv Contents INTRODUCTION 1 How This Book Is Organized..................................................................1 Part I:Understanding COM+ Applications........................................1 Part II:Data Services..........................................................................2 Part III:Business Services..................................................................3 Part IV:User Services........................................................................3 Part V:PubsOnLine.com....................................................................4 Conventions Used in This Book..............................................................5 PART I UNDERSTANDINGCOM+ APPLICATIONS 7 1 WINDOWSDNAANDCOM+ 9 Windows 2000 Services........................................................................11 Active Directory ..............................................................................12 Internet Information Server 5.0........................................................12 Message Queuing ............................................................................14 Universal Data Access......................................................................14 XML Support....................................................................................14 Network Load Balancing..................................................................16 Component Services ........................................................................16 Tiered Architecture Overview................................................................18 Two-Tier Architecture......................................................................19 Three-Tier Architecture....................................................................21 Establishing a Test Environment ..........................................................23 Windows 2000 Advanced Server......................................................24 SQL Server 2000..............................................................................26 Visual Studio....................................................................................26 2 ADMINISTERINGCOM+ 27 The Component Services Explorer........................................................28 Computer Properties ........................................................................29 Application Properties......................................................................34 The System Application ..................................................................40 Creating Applications ......................................................................40 Component Properties......................................................................42 Installing COM+ Components into an Application ........................46 3 DESIGNINGCOM+ APPLICATIONS 53 Assessing Functional Requirements......................................................54 Problem Statement............................................................................54 Gathering Requirements ..................................................................55 Assessing Requirements ..................................................................57 00 973x FM 8/28/00 2:22 PM Page v Describing the System ..........................................................................58 Identifying Actors and Use Cases....................................................59 Documenting the Use Cases............................................................60 Flow Charts......................................................................................64 Creating the Paper Prototype ................................................................65 System Modeling..............................................................................66 Database Model................................................................................66 Logical Model..................................................................................67 Three-Tier Diagram..........................................................................69 4 COM+ APPLICATIONFUNDAMENTALS 83 Understanding Contexts........................................................................84 Object Activation ..................................................................................88 Communicating with the Context....................................................93 State Management............................................................................96 The ObjectControl Interface............................................................99 Managing Shared Properties................................................................102 SharedPropertyGroupManager................................................102 SharedPropertyGroup................................................................102 SharedProperty..........................................................................103 PART II DATASERVICES 111 5 ACCESSINGDATAWITHCOM+ 113 OLEDB Session Pooling ....................................................................114 Controlling the Number of Pools ..................................................115 Tuning Session Pooling..................................................................117 Understanding Data Transportation ....................................................123 Understanding Cursors ..................................................................123 Understanding Transports and Payloads........................................125 Delimited Strings............................................................................126 Variant Arrays ................................................................................127 Disconnected Recordsets................................................................129 Property Bags ................................................................................131 Conclusion......................................................................................134 XML....................................................................................................134 XML Fundamentals........................................................................135 The Stream Object..........................................................................139 Web Services and SOAP................................................................141 Updating Records................................................................................142 Handling Collisions........................................................................143 00 973x FM 8/28/00 2:22 PM Page vi vi SCOTHILLIER’SCOM+ PROGRAMMINGWITHVISUALBASIC 6 COM+ DATACOMPONENTS 149 Encapsulating Stored Procedures........................................................151 Parameter Passing................................................................................154 Strong Function Signatures............................................................154 Variant Arrays ................................................................................155 XML ..............................................................................................158 Error Handling ....................................................................................161 Polymorphic Interfaces........................................................................163 Understanding Polymorphism........................................................164 Creating Standards..........................................................................165 The DNA Payload................................................................................167 Overview........................................................................................169 Dataset Properties and Methods ....................................................169 Field Object Properties ..................................................................170 Passing Parameters with the DNA Payload ..................................170 Returning Data with the DNA Payload..........................................173 Displaying HTML with the DNA Payload....................................174 Conclusion ..........................................................................................175 7 COM+ TRANSACTIONS 181 Understanding Transaction Attributes ................................................182 The Microsoft Distributed Transaction Coordinator ..........................183 Transactional Components..................................................................184 Understanding Transaction Context ..............................................185 Voting in Transactions....................................................................190 Monitoring Transactions......................................................................198 PART III BUSINESSSERVICES 205 8 COM+ SECURITY 207 Distributed Security ............................................................................208 Certificates......................................................................................208 Kerberos Protocol ..........................................................................209 Active Directory..................................................................................210 Single Sign-On ..............................................................................211 Microsoft Installer..........................................................................211 Personalization................................................................................212 Active Directory Services Interface....................................................213 Using ADSI....................................................................................213 Manipulating Properties ................................................................216 Authenticating Users......................................................................220 COM+ Security Features ....................................................................222 Declarative Security ......................................................................222 Programmatic Security ..................................................................223 Conclusion ..........................................................................................226 00 973x FM 8/28/00 2:22 PM Page vii vii CONTENTS 9 COM+ BUSINESSFEATURES 231 The COM+ Event System....................................................................232 Event Classes..................................................................................233 Event Subscribers ..........................................................................234 Event Publishers ............................................................................237 Filtering Events..............................................................................238 COM+ Constructors............................................................................238 Compensating Resource Manager System..........................................242 CRM Workers ................................................................................242 CRM Clerks....................................................................................243 Compensating Resource Managers................................................245 CRM Issues....................................................................................249 10 ASYNCHRONOUSCOM+ APPLICATIONS 255 The Microsoft Message Queue............................................................256 MSMQ Applications............................................................................258 MSMQApplication Object ............................................................258 MSMQQuery Object......................................................................259 MSMQQueueInfos Object..............................................................260 MSMQQueueInfo Object ..............................................................260 MSMQQueue Object......................................................................261 MSMQEvent Object ......................................................................261 MSMQMessage Object..................................................................262 MSMQ Limitations........................................................................264 Queued Components............................................................................265 Designing Queued Components ....................................................266 Calling Queued Components..........................................................268 Using Queued Components in Transactions..................................271 Exception Classes ..........................................................................272 PART IV USERSERVICES 279 11 COM+ ANDTHEINTERNET 281 New Internet Information Server Features..........................................282 Isolating Internet Applications ......................................................282 Generating Custom Error Messages..............................................285 Using Scriptless ASP......................................................................290 Creating Transactional Web Pages......................................................290 Understanding Transactional Attributes ........................................290 Creating Multi-Page Transactions..................................................292 Creating Classes in Scripts ............................................................294 00 973x FM 8/28/00 2:22 PM Page viii viii SCOTHILLIER’SCOM+ PROGRAMMINGWITHVISUALBASIC Accessing ASP Objects with COM+ Components..............................298 Understanding XSL Style Sheets........................................................300 XSL Fundamentals ........................................................................300 XSL Templates ..............................................................................302 XSL Elements................................................................................305 12 COM+ ANDWIN32 311 Maintaining Application State ............................................................312 Custom Collections........................................................................314 Data Binding..................................................................................315 User Interface Strategies......................................................................319 ActiveX Controls............................................................................319 HTA Pages......................................................................................324 13 INTEGRATINGCOM+WITHGROUPWARE 331 Integrating Exchange 2000 Server with COM+..................................332 Understanding Web Storage ..........................................................332 ActiveX Data Objects:Accessing Web Stores ..............................334 Collaboration Data:Using Contact and Message Objects ............336 Integrating Microsoft Outlook 2000 with COM+ ..............................338 The Outlook Design Environment ................................................340 Coding Outlook Items....................................................................343 Integrating Digital Dashboards with COM+ ......................................348 14 DEBUGGINGANDDEPLOYINGCOM+ APPLICATIONS 353 Debugging COM+ Components..........................................................354 Debugging in Visual Basic ............................................................354 Debugging in Visual InterDev........................................................355 Deploying COM+ Applications ..........................................................356 Deploying Data Services................................................................357 Deploying Business Services ........................................................357 Deploying User Services................................................................359 Deployment Checklist....................................................................362 Analyzing COM+ Applications ..........................................................363 The Testing Process........................................................................364 Assessing Performance..................................................................366 Load Balancing..............................................................................367 15 COM+ CATALOGADMINISTRATION 377 The COM+ Administration Object Model..........................................378 TheCOMAdminCatalogObject ....................................................378 TheCOMAdminCatalogCollectionObject................................380 TheCOMAdminCatalogObjectObject........................................382 00 973x FM 8/28/00 2:22 PM Page ix ix CONTENTS Performing COM+ Administration with the Windows Scripting Host....................................................................................383 The WScript Object........................................................................384 The Shell Object ............................................................................385 PART V PUBSONLINE.COM 389 16 DESIGNINGTHEPUBSONLINE.COMAPPLICATION 391 Problem Statement ..............................................................................392 Gathering Requirements......................................................................392 Membership and Personalization ..................................................393 Promotions......................................................................................393 Analysis..........................................................................................393 Identifying Actors and Use Cases........................................................393 Log In ............................................................................................394 Add Book to Cart ..........................................................................397 View Cart........................................................................................399 Checkout ........................................................................................401 Screen Shots and the Paper Prototype ................................................403 Data Model..........................................................................................407 System Models....................................................................................408 The Three-Tier Model....................................................................408 Log In ............................................................................................410 Add Book to Cart ..........................................................................412 Check Out ......................................................................................414 Defining Components..........................................................................415 17 BUILDINGTHEPUBSONLINE.COMAPPLICATION 417 Development Environment..................................................................418 Creating the Database..........................................................................419 Creating the COM+ Components........................................................425 Data Services..................................................................................428 Business Services ..........................................................................436 Deploying Components..................................................................440 Creating the Web Interface..................................................................445 Index 449 02 973x Part I 8/28/00 2:18 PM Page 7 PART Understanding COM+ I Applications IN THIS PART 1 Windows DNA and COM+ 9 2 Administering COM+ 27 3 Designing COM+ Applications 53 4 COM+ Application Fundamentals 83 03 973x CH01 8/28/00 2:22 PM Page 9 Windows DNA and COM+ CHAPTER 1 IN THIS CHAPTER • Windows 2000 Services 11 • Tiered Architecture Overview 18 • Establishing a Test Environment 23