Programming .NET 3.5 Other Microsoft .NET resources from O’Reilly Related titles .NET Windows Forms in a Building a Web 2.0 Portal Nutshell with ASP.NET 3.5 ADO.NET 3.5 Cookbook™ Learning ASP.NET 3.5 ADO.NET 3.5 in a Nutshell Programming ASP.NET AJAX .NET Books dotnet.oreilly.com is a complete catalog of O’Reilly’s books on Resource Center .NET and related technologies, including sample chapters and code examples. ONDotnet.comprovidesindependentcoverageoffundamental, interoperable,andemergingMicrosoft.NETprogrammingand web services technologies. Conferences O’Reillybringsdiverseinnovatorstogethertonurturetheideas thatsparkrevolutionaryindustries.Wespecializeindocument- ing the latest tools and systems, translating the innovator’s knowledge into useful skills for those in the trenches. Visit conferences.oreilly.com for our upcoming events. Safari Bookshelf (safari.oreilly.com) is the premier online refer- ence library for programmers and IT professionals. Conduct searchesacrossmorethan1,000books.Subscriberscanzeroin on answers to time-critical questions in a matter of seconds. Read the books on your Bookshelf from cover to cover or sim- ply flip to the page you need. Try it today for free. Programming .NET 3.5 Jesse Liberty and Alex Horovitz Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo Programming .NET 3.5 by Jesse Liberty and Alex Horovitz Copyright © 2008 Jesse Liberty and Alex Horovitz. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 [email protected]. Editor: John Osborn Indexer: Ellen Troutman Zaig Production Editor: Rachel Monaghan Cover Designer: Karen Montgomery Copyeditor: Rachel Head Interior Designer: David Futato Proofreader: Rachel Monaghan Illustrator: Jessamyn Read Printing History: July 2008: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc.Programming .NET 3.5, the image of a giant petrel, and related trade dress are trademarks of O’Reilly Media, Inc. Java™ is a trademark of Sun Microsystems, Inc. .NET is a registered trademark of Microsoft Corporation. Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedas trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. This book uses RepKover™, a durable and flexible lay-flat binding. ISBN: 978-0-596-52756-3 [M] This book is dedicated to the simple idea of human respect, which entails the incredibly difficult process of actually listening to one another with an open mind. —Jesse Liberty To my spouse, Torri, and my three boys, Daniel, Zachary, and Jason. Together our adventure continues. Each day brings new opportunities and the chance to build on the accomplishmentsofthedaybefore.Neverstop living to make today the best day of your life. —Alex Horovitz Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Part I. Presentation Options 1. .NET 3.5: A Better Framework for Building MVC, N-Tier, and SOA Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Integration Versus Silos 4 What? All That in One Book? 5 2. Introducing XAML: A Declarative Way to Create Windows UIs . . . . . . . . . . . . . 7 XAML 101 8 Simple XAML Done Simply 10 Over Here…No, Wait, I Meant Over There! 23 It’s Alive! (Or, How I Learned to Stop Worrying and Love Animation) 32 3. Introducing Windows Presentation Foundation: A Richer Desktop UI Experience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Starting Simple: Panels 46 Nesting 65 Resources 67 Transformations 68 Animation 69 Data Binding 76 vii 4. Applying WPF: Building a Biz App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Breaking the Application into Pieces 90 Adorners 90 Business Classes 95 Page 1—Adding Items to the Shopping Cart 99 Page 2—Validating the Credit Card 124 5. Introducing AJAX: Moving Desktop UIs to the Web . . . . . . . . . . . . . . . . . . . . 137 Web Applications Just Got a Whole Lot Faster 137 Getting Started 139 Creating a “Word Wheel” with AJAX 141 ScriptManager 151 What’s Next? 160 6. Applying AJAX: ListMania . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Creating the To-Do List Manager 161 Personalizing the To-Do List 180 7. Introducing Silverlight: A Richer Web UI Platform. . . . . . . . . . . . . . . . . . . . . 195 Silverlight in One Chapter 195 The Breadth of Silverlight 196 Diving Deep: Building an Application 196 Controls 197 Events and Event Handlers 207 Creating Controls Dynamically 212 Data Binding 215 Styling Controls 221 Part II. Interlude on Design Patterns 8. Implementing Design Patterns with .NET 3.5. . . . . . . . . . . . . . . . . . . . . . . . . 227 .NET 3.5 Fosters Good Design 228 The N-Tier Pattern 231 The MVC Pattern 232 The Observer Pattern/Publish and Subscribe 249 The Factory Method Pattern 258 The Chain-of-Command Pattern 266 The Singleton Pattern 274 viii | Table of Contents Part III. The Business Layer 9. Understanding LINQ: Queries As First-Class Language Constructs . . . . . . . 283 Defining and Executing a LINQ Query 284 Extension Methods 297 Adding the AdventureWorksLT Database 305 LINQ to SQL Fundamentals 308 Using the Visual Studio LINQ to SQL Designer 313 Retrieving Data 317 LINQ to XML 322 10. Introducing Windows Communication Foundation: Accessible Service-Oriented Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 Defining a Service More Precisely 328 Implementing Web Services 332 UDDI: Who Is Out There, and What Can They Do for Me? 337 How It All Works 338 WCF’s SOA Implementation 339 Putting It All Together 343 11. Applying WCF: YahooQuotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 Creating and Launching a Web Service 346 Consuming the Web Service 355 12. Introducing Windows Workflow Foundation . . . . . . . . . . . . . . . . . . . . . . . . . 365 Conventional (Pre-WF) Flow Control 365 Using Windows Workflow 371 Understanding the WF Runtime 383 Workflow Services 383 13. Applying WF: Building a State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386 Windows Workflow and State Machines 387 Building an Incident Support State Machine 387 14. Using and Applying CardSpace: A New Scheme for Establishing Identity. . . . 408 About Windows CardSpace 409 Creating a CardSpace Identity 413 Adding CardSpace Support to Your Application 418 Summary 435 Table of Contents | ix
Description: