Smart Client Architecture
ContentsForeword viiChapter 1Introduction 1What Is a Smart Client? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Rich Client Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Thin Client Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Smart Client Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Types of Smart Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Windows Smart Client Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Office Smart Client Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Mobile Smart Client Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Choosing Between Smart Clients and Thin Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Smart Client Architectural Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Scope of This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13How to Use This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Who Should Read This Guide. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Chapter Outlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Chapter 1: Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Chapter 2: Handling Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Chapter 3: Getting Connected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Chapter 4: Occasionally Connected Smart Clients . . . . . . . . . . . . . . . . . . . . . . . . . 15Chapter 5: Security Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Chapter 6: Using Multiple Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Chapter 7: Deploying and Updating Smart Client Applications . . . . . . . . . . . . . . . . . 16Chapter 8: Smart Client Application Performance . . . . . . . . . . . . . . . . . . . . . . . . . . 16Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Chapter 2Handling Data 17Types of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Read-Only Reference Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Transient Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Caching Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19The Caching Application Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Data Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24iv Smart Client Architecture and Design GuideUsing ADO.NET DataSets to Manage Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Merging Data with Datasets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Increasing the Performance of Datasets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Windows Forms Data Binding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Windows Forms Data Binding Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Binding Data to Windows Forms Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Chapter 3Getting Connected 39Loosely Coupled and Tightly Coupled Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39Communication Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40.NET Enterprise Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40.NET Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Message Queuing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Choosing a Communication Option. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Designing Connected Smart Client Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48Use Coarse-Grained, Encapsulated Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48Avoid Distributed ACID Transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48Avoid Sending Datasets Across the Network. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49Break Up Large Datasets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49Version Your Web Services and Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Chapter 4Occasionally Connected Smart Clients 51Common Occasionally Connected Scenarios. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Occasionally Connected Design Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53The Data-Centric Approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55The Service-Oriented Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Designing Occasionally Connected Smart Client ApplicationsUsing a Service-Oriented Approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Favoring Asynchronous Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Minimizing Complex Network Interactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Adding Data Caching Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Managing Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Designing Store-and-Forward Mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Managing Data and Business Rule Conflicts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Interacting with CRUD-Like Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71Using a Task-Based Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Handling Dependencies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Contents vChapter 5Security Considerations 79Authentication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Smart Client Authentication Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Choosing the Right Authentication Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Network Access Authentication Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84Gathering and Validating User Credentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Authentication Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91Authorization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Types of Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Adding Authorization Capabilities to Your Application. . . . . . . . . . . . . . . . . . . . . . . . 94Authorization Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Authorizing Functionality When the Client Is Offline . . . . . . . . . . . . . . . . . . . . . . . . . 96The Authorization and Profile Application Block. . . . . . . . . . . . . . . . . . . . . . . . . . . . 97Input Validation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97Handling Sensitive Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98Determining Which Data to Store on the Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Techniques for Protecting Sensitive Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100Code Access Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102Code Access Security Permission Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Designing for Code Access Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112Chapter 6Using Multiple Threads 113Multithreading in the .NET Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113Choosing Between Synchronous and Asynchronous Calls . . . . . . . . . . . . . . . . . . . 114Choosing Between Foreground and Background Threads . . . . . . . . . . . . . . . . . . . . 114Handling Locking and Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Using Timers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116When to Use Multiple Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Communicating Over a Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118Performing Local Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118Distinguishing Tasks of Varying Priority. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Application Startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Creating and Using Threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Using the ThreadPool Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Using the Thread Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121Using Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122Calling Web Services Asynchronously. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Using Tasks to Handle Interaction Between the UI Thread and Other Threads. . . . . . . 126Defining a Task Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129Using the Task Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136vi Smart Client Architecture and Design GuideChapter 7Deploying and Updating Smart Client Applications 137Deploying the .NET Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138Preinstalling the .NET Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139Installing the .NET Framework with an Application . . . . . . . . . . . . . . . . . . . . . . . . . 139Deploying Smart Client Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140No-Touch Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141No-Touch Deployment with an Application Update Stub . . . . . . . . . . . . . . . . . . . . . 144Running Code from a File Share. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Xcopy Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Windows Installer Packages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Choosing the Right Deployment Approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149Deploying Smart Client Updates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151No-Touch Deployment Updates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152Automatic Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152Updates from a File Share . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Xcopy Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Windows Installer Updates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154Choosing the Right Update Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156Chapter 8Smart Client Application Performance 157Designing for Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158Data Caching Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160Network Communications Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161Threading Guidelines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161Transaction Guidelines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Optimizing Application Startup Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Managing Available Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165Optimizing Windows Forms Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169Performance Tuning and Diagnosis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Setting Performance Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Performance Tuning Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177Performance Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
.NET Framework Essentials
.NET Framework Essentials is a concise and technical overview of the new Microsoft .NET Framework.<br>Covered here are all of the most important topics—from the underlying Common Language Runtime<br>(CLR) to its speci alized packages for ASP.NET, Web Forms, Windows Forms, XML and data access<br>(ADO.NET). The authors survey each of the major .NET languages, including VB.NET, C# and<br>Managed C++.
Programming WCF Services
Programming WCF Services--O'Reilly