Distributed Data Applications with ASP.NET, Second Edition ALEX HOMER AND DAVID SUSSMAN APress Media, LLC Distributed Data Applications with ASP.NET, Second Edition Copyright © 2004 by Alex Homer and David Sussman Originally published by Apress in 2004 AlI rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN 978-1-59059-318-9 ISBN 978-1-4302-0661-3 (eBook) DOI 10.1007/978-1-4302-0661-3 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Technical Reviewers: Dan Green, John Godfrey, Maxime Bombardier, Christian Holm, Jeffrey Hasan, Paul Churchill, Phil Powers-De George, Fredrik Normen, Christophe Nasarre, Andrew Stopford, Larry Schoeneman, Sophie McQueen, David Schultz, Johan Normen Editorial Board: Steve Anglin, Dan Appleman, Gary Cornell, James Cox, Tony Davis, John Franklin, Chris Mills, Steven Rycroft, Dominic Shakeshaft, Julian Skinner, Martin Streicher, Iim Sumser, Karen Watterson, Gavin Wray, John Zukowski Assistant Publisher: Grace Wong Project Manager: Beth Christmas Copy Editor: Kim Wimpsett Production Manager: Kari Brooks Production Editor: JanetVail Proofreader: Linda Seifert Compositor: Diana Van Winkle, Van Winkle Design Indexer: Valerie Robbins Cover Designer: Kurt Krames Manufacturing Manager: Tom Debo1ski In the United States: phone 1-800-SPRINGER, email [email protected]. or visit http://www.springer-ny . corn. Outside the United States: fax +49 6221 345229, email [email protected], or visit http://www.springer.de. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, email [email protected], or visit http://www.apress.com. The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any 10ss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is avai1able to readers at http://www.apress.comin the Downloads section. Contents at a Glance About the Authors ............................................................................................ xiii Introduction ........................................................................................................ xv Chapter 1 The Distributed Application .............................................. 1 Chapter 2 Components and Data Access .............................................. 53 Chapter 3 Accessing XML Documents ................................................... 109 Chapter 4 The Application Plumbing ................................................ 143 Chapter 5 Working with Down-Level Clients ................................. 199 Chapter 6 Working with Rich Clients .............................................. 261 Chapter 7 Remoting to .NET Clients ................................................ 347 Chapter 8 Updating Data in Down-Level Clients ........................ 391 Chapter 9 Updating Remote Cached Data ........................................ .475 Chapter 10 Components for Updating Data ........................................ 527 Chapter 11 Rich Client Update Applications ................................. 583 Chapter 12 Reconciling Update Errors .............................................. 647 Chapter 13 Updating Data from Remote .NET Applications ....... 715 Index ...................................................................................................................... 765 iii Contents About the Authors ............................................................................................ xiii Introduction ........................................................................................................ xv Chapter 1 The Distributed Application ................................... 1 What Are Distributed Data Applications? ............................................... 2 Our Definition .................................................................................................... 2 Why Do You Need to Distribute? ....................................................................... 3 How Can You Do ((Distributed}) on the Internet? .................................. 5 Internet Protocols ............................................................................................... 5 Internet Clients ................................................................................................... 6 The Elements of a Distributed Application ........................................... 8 Client Devices and Client Applications .......................................................... 10 Server-Side Data Stores .................................................................................... 12 Processing and Presenting Information ......................................................... 14 Data Access Techniques Overview .............................................................. .20 About "Relational" Data Access ....................................................................... 21 The ADO. NET Data Access Classes ................................................................. 22 Understanding System.Xml .............................................................................. 32 Representing Data and Information ............................................................... 33 The System.XrnI Classes ................................................................................... 37 Data Access and the n-Tier Model ............................................................ .41 What Is the Data Being Used For? ................................................................... 41 Some n -Tier Data Access Scenarios ............................................................... .44 Summary ................................................................................................................... 51 Chapter 2 Components and Data Access .................................... 53 Different Types of ((Component}) ................................................................. 54 .NET Components ............................................................................................ 54 COM and COM+ Components ........................................................................ 58 User Controls .................................................................................................... 59 Include Files ...................................................................................................... 63 Server Controls ................................................................................................. 64 Accessing and Exposing Data ........................................................................ 64 Delivering Data to Rich Clients ....................................................................... 64 Managing Data for Down-Level Clients ......................................................... 65 Displaying XML Data ....................................................................................... 65 v Contents Working with the DataSet Object ............................................................... 66 The Structure of the DataSet Object ............................................................... 66 When Should You Use a DataSet? .................................................................... 69 Relational Data Access Component Examples ........................................ 70 Setting Up the Examples .................................................................................. 70 Accessing and Returning Relational Data ...................................................... 72 Summary ................................................................................................................ 107 Chapter 3 Accessing XML Documents .......................................... 109 Introducing the XML Data Access Component Examples .................. 109 Accessing and Returning Relational Data .......................................... 110 Using the SupplierListXml Data Access Component .................................. 111 Returning an XmITextReader Reference ....................................................... 112 Returning an XmlValidatingReader Reference ............................................ 11 8 Returning a DataSet Object ........................................................................... 123 Returning a Custom Array Reference ........................................................... 126 Returning an ArrayList Reference ................................................................. 130 Returning an XML String ............................................................................... 133 Returning an XmIDocument Object ............................................................. 135 Returning anXPathDocument Object .......................................................... 137 Summary ................................................................................................................ 141 Chapter 4 The Application Plumbing ....................................... 143 Overview of Client-Side Techniques ..................................................... 144 Available Client-Side Programming Techniques ......................................... 144 Choosing Client Support ............................................................................... 145 Remoting Data to the Client .................................................................... 151 Remoting Relational Data to the Client ........................................................ 151 Remoting XML Data to the Client ................................................................. 154 Running the .NET Framework on the Client ................................................ 157 Using ASP. NET Sessions ............................................................................... 172 Sessions Configuration in ASP. NET .............................................................. 172 Checking for Session Support ....................................................................... 175 Munging URLs for Session Support .............................................................. 176 Client Detection Example ........................................................................... 177 Overview of the Process ................................................................................. 177 Detecting the Client Type .............................................................................. 178 The default.aspxPage .................................................................................... 182 Detection Errors and Unsupported Clients ................................................. 184 Checking for Client- Side Scripting Support ................................................. 1 84 vi Contents Redirecting the Client If Scripting Is Enabled .............................................. 185 The Device-Specific Home Pages .................................................................. 186 Viewing the Results ........................................................................................ 191 Summary ................................................................................................................ 196 Chapter 5 Working with Down-Level Clients ..................... 199 A Mul tiple-Client Order List Application ........................................ 200 The User Interface ..........................................................................................2 01 Detecting the Client Type ......................................................................... 202 The Data Access Tier .................................................................................... 206 Maximizing Efficiency Through Data Caching ............................................ 206 The Order List Application: The HTML Version ............................... 207 The Outline Process .......................................................................................2 08 Searching for Customers ................................................................................2 09 Displaying a List of Customers ...................................................................... 211 Displaying a List of Orders ............................................................................. 220 Displaying the Order Details ......................................................................... 229 The Order List Application: The Mobile Version ........................... 235 The Outline Process ....................................................................................... 236 Fetching Data from the Server ...................................................................... 238 The Mobile Page Content .............................................................................. 242 Summary ................................................................................................................ 259 Chapter 6 Working with Rich Clients ..................................... 261 Working wi th XML ............................................................................................ 262 Why XSL and XSLT? ........................................................................................ 262 Exposing and Delivering niL ....................................................................... 262 Using XML in Internet Explorer 5 and Higher ................................. 264 Building the Middle Tier ................................................................................ 264 Selecting a Customer ..................................................................................... 271 Selecting an Order .......................................................................................... 285 Viewing Order Details .................................................................................... 293 Extracting the Order Details .......................................................................... 294 Using Web Services in Internet Explorer 5 and Higher .............. 297 Looking at the Customer Data Web Service ................................................. 298 Testing a Web Service ..................................................................................... 300 Building the Middle Tier ................................................................................ 302 The Internet Explorer 5 WebService Behavior ............................................. 305 vii Contents Building the Hypertext Application Example ................................... 310 Running the Example Hypertext Application .............................................. 311 Loading the XML Data ................................................................................... 313 Building the Middle Tier ................................................................................ 314 The HTA Page Content ................................................................................... 316 Selecting an Order .......................................................................................... 323 Working with Delimited Text Data ......................................................... 324 Why Use Delimited Text Data? ...................................................................... 324 Remember the TDC? ...................................................................................... 324 Building the Middle Tier ................................................................................ 325 Selecting a Customer ..................................................................................... 331 Selecting and Viewing an Order .................................................................... 338 Client -Side Data Binding with XML Anyone? .............................................. 345 Summary ................................................................................................................ 345 Chapter 7 Remoting to . NET Clients ....................................... 347 Remoting Refresher ......................................................................................... 348 Remoting Objects .............................................................................................. 348 The Remotable Object Class .......................................................................... 349 The Remote Server ......................................................................................... 349 The Remote Client .......................................................................................... 352 Deploying the Objects .................................................................................... 356 The Windows Application .............................................................................. 356 The Design Choices ........................................................................................ 359 Remoting Data to Windows Applications ..................................................... 359 Building the Windows Application ............................................................... 360 Creating the Web Services .............................................................................. 364 Incremental Downloads ................................................................................... 368 Creating a Downloadable Form .................................................................... 368 Loading the Form Dynamically ..................................................................... 369 The Download Cache ..................................................................................... 372 Strong Named Assemblies and the Download Cache ................................. 374 Deployment ........................................................................................................... 374 Security ............................................................................................................... 375 Security Policy ................................................................................................ 377 Modifying the Security Policy ........................................................................ 379 Checking Permissions .................................................................................... 386 Dynamic Applications .................................................................................... .388 Summary ................................................................................................................ 389 viii Contents Chapter 8 Updating Data in Down-Level Clients ........... 391 Updating Data Stores: An Overview ........................................................ 392 Making the Process As Efficient As Possible ................................................. 392 Measuring the Results and Providing Feedback .......................................... 394 Controlling Access to Protect the Data ......................................................... 394 Controlling Concurrent Data Updates ......................................................... 395 Data Update Techniques in .NET ............................................................... 397 Using Transactions While Updating Data .................................................... .404 Managing Concurrency While Updating ...................................................... 408 Data Update Example for HTML 3.2 Clients ........................................ .412 An Overview of the Application .................................................................... 413 Displaying and Editing Orders ...................................................................... 418 Displaying and Editing the Order Contents ................................................ .452 Data Update Example for Mobile Devices .............................................. 467 The Application Design ................................................................................. 467 Viewing the Application ................................................................................. 469 Summary ................................................................................................................. 473 Chapter 9 Updating Remote Cached Data .............................. .475 Reviewing the Architecture ........................................................................ 476 Caching Updates on the Client ..................................................................... 477 Getting Updates Back to the Server .............................................................. 478 Loading a DataSet .......................................................................................... 480 Executing the Update Process .................................................................. .498 Providing Feedback from the Update Process ............................................ .499 The Update Process in Detail ........................................................................ 503 A Data Update Process Example ................................................................... 505 Summary .................................................................................................................5 25 Chapter 10 Components for Updating Data ............................. 527 The UpdateDataSet Component ...................................................................... 528 Enabling Tracing from Within a Component ............................................... 528 Writing to the Trace Object ............................................................................ 530 The Common Methods in the Component .................................................. 532 Managing IDENTITY Columns for Inserted Rows ....................................... 533 The UpdateAlIOrderDetails Method ............................................................. 549 Creating the Parameterized Command Objects .......................................... 563 ix Contents Using the UpdateDataSet Component ....................................................... 570 Filling the DataSet .......................................................................................... 572 Editing Some RowValues ............................................................................... 573 Changing the Underlying Database Values Concurrently .......................... 575 Performing the Update .................................................................................. 577 Displaying the Update Errors ........................................................................ 578 Deleting the New Rows You Added ............................................................... 580 Viewing the Trace Information ...................................................................... 581 Summary ................................................................................................................ 582 Chapter 11 Rich Client Update Applications ..................... 583 How This Chapter Is Organized ................................................................ 584 An Overview of the Application .............................................................. 585 The Process in Outline ................................................................................... 586 Checking for Concurrency Errors ................................................................. 587 The Middle Tier ASP. NET Page .................................................................. 587 Getting the Data from the Data Access Tier ................................................. 588 Exposing the Data to the Client ..................................................................... 588 Loading the Di ffgrams on the Client ................................................... 589 Loading the Orders Data ................................................................................ 590 Loading the Shippers Data ............................................................................ 591 Loading the Products Data ............................................................................ 593 Editing a .NET DataSet Diffgram ........................................................... 594 Viewing the Updated Diffgram ..................................................................... 595 The Updated Diffgram Format ...................................................................... 598 The edit-orders. aspx Page Code and HTML .......................................... 603 Creating the List of Orders ............................................................................. 603 Posting the Updated Diffgram to the Server ................................................ 605 Displaying Details of the Selected Order ...................................................... 609 Creating the List of Order Lines .................................................................... 616 Creating the Update Line and Delete Line Buttons ..................................... 618 It's Time to Talk Dirty ...................................................................................... 618 Updating the Orders Diffgram ...................................................................... 620 Summary ................................................................................................................ 644 Chapter 12 Reconciling Update Errors ..................................... 647 Reconciling Update Errors in Overview .............................................. 648 A Summary of the Process ............................................................................. 648 The Error Reporting and Reconciliation Process ......................................... 649 Displaying Trace Information ....................................................................... 654 x
Description: