1 YEAR UPGRADE BUYER PROTECTION PLAN Develop and Deliver Enterprise-Critical Desktop and Web Applications with C# .NET • Complete Case Studies with Ready-to-Run Source Code and Full Explanations • Hundreds of Developing & Deploying, Migrating, and Debugging Sidebars, Security Alerts, and C# .NET FAQs • Complete Coverage of Web Services and the Integrated Development Environment (IDE) Adrian Turtschi DotThatCom.com Jason Werry Greg Hack Joseph Albahari Saurabh Nandu Technical Editor Wei Meng Lee Series Editor C# .NET Web Developer’s Guide solutions@syngress.com With more than 1,500,000 copies of our MCSE, MCSD, CompTIA, and Cisco study guides in print, we continue to look for ways we can better serve the information needs of our readers. One way we do that is by listening. Readers like yourself have been telling us they want an Internet-based ser- vice that would extend and enhance the value of our books. Based on reader feedback and our own strategic plan, we have created a Web site that we hope will exceed your expectations. Solutions@syngress.com is an interactive treasure trove of useful infor- mation focusing on our book topics and related technologies. The site offers the following features: ■ One-year warranty against content obsolescence due to vendor product upgrades. You can access online updates for any affected chapters. ■ “Ask the Author” customer query forms that enable you to post questions to our authors and editors. ■ Exclusive monthly mailings in which our experts provide answers to reader queries and clear explanations of complex material. ■ Regularly updated links to sites specially selected by our editors for readers desiring additional reliable information on key topics. Best of all, the book you’re now holding is your key to this amazing site. Just go to www.syngress.com/solutions, and keep this book handy when you register to verify your purchase. Thank you for giving us the opportunity to serve your needs. And be sure to let us know if there’s anything else we can do to help you get the maximum value from your investment. We’re listening. www.syngress.com/solutions 167_C#_FM.qxd 12/5/01 10:16 AM Page i 167_C#_FM.qxd 12/5/01 10:16 AM Page ii 1 YEAR UPGRADE BUYER PROTECTION PLAN Adrian Turtschi DotThatCom.com Jason Werry Greg Hack Joseph Albahari Saurabh Nandu Technical Editor Wei Meng Lee Series Editor C# .NET Web Developer’s Guide 167_C#_FM.qxd 12/5/01 10:16 AM Page iii Syngress Publishing, Inc., the author(s), and any person or firm involved in the writing, editing, or production (collectively “Makers”) of this book (“the Work”) do not guarantee or warrant the results to be obtained from the Work. There is no guarantee of any kind, expressed or implied, regarding the Work or its contents.The Work is sold AS IS and WITHOUT WARRANTY. You may have other legal rights, which vary from state to state. In no event will Makers be liable to you for damages, including any loss of profits, lost savings, or other incidental or consequential damages arising out from the Work or its contents. Because some states do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation may not apply to you. You should always use reasonable care, including backup and other appropriate precautions, when working with computers, networks, data, and files. Syngress Media®, Syngress®,“Career Advancement Through Skill Enhancement®,” and “Ask the Author UPDATE®,” are registered trademarks of Syngress Publishing, Inc. “Mission Critical™,”“Hack Proofing™,” and “The Only Way to Stop a Hacker is to Think Like One™” are trademarks of Syngress Publishing, Inc. Brands and product names mentioned in this book are trademarks or service marks of their respective companies. KEY SERIAL NUMBER 001 CDFE48952P 002 NHBN9436KH 003 BAEN24P7BV 004 HY9W84UJTA 005 RTW9B39RE4 006 JSE4FAHT82 007 VTS8TYCGF2 008 AUTGFLDCWR 009 833K74SLAF 010 VFR4MHY3XW PUBLISHED BY Syngress Publishing, Inc. 800 Hingham Street Rockland, MA 02370 C# .NET Web Developer’s Guide Copyright © 2002 by Syngress Publishing, Inc. All rights reserved. Printed in the United States of America. Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication. Printed in the United States of America 1 2 3 4 5 6 7 8 9 0 ISBN: 1-928994-50-4 Technical Editor: Saurabh Nandu Freelance Editorial Manager: Maribeth Corona-Evans Co-Publisher: Richard Kristof Cover Designer: Michael Kavish Acquisitions Editor: Catherine B. Nolan Page Layout and Art by: Shannon Tozier Developmental Editor: Kate Glennon Copy Editor: Darren Meiss CD Production: Michael Donovan Indexer: Rich Carlson Distributed by Publishers Group West in the United States and Jaguar Book Group in Canada. 167_C#_FM.qxd 12/5/01 10:16 AM Page iv vv We would like to acknowledge the following people for their kindness and support in making this book possible: Richard Kristof and Duncan Anderson of Global Knowledge, for their generous access to the IT industry’s best courses, instructors, and training facilities. Ralph Troupe, Rhonda St. John, and the team at Callisma for their invaluable insight into the challenges of designing, deploying and supporting world-class enterprise networks. Karen Cross, Lance Tilford, Meaghan Cunningham, Kim Wylie, Harry Kirchner, Kevin Votel, Kent Anderson, and Frida Yara of Publishers Group West for sharing their incredible marketing experience and expertise. Mary Ging, Caroline Hird, Simon Beale, Caroline Wheeler,Victoria Fuller, Jonathan Bunkell, and Klaus Beran of Harcourt International for making certain that our vision remains worldwide in scope. Annabel Dent of Harcourt Australia for all her help. David Buckland,Wendi Wong, Marie Chieng, Lucy Chong, Leslie Lim, Audrey Gan, and Joseph Chan of Transquest Publishers for the enthusiasm with which they receive our books. Kwon Sung June at Acorn Publishing for his support. Ethan Atkin at Cranbury International for his help in expanding the Syngress program. Jackie Gross, Gayle Vocey, Alexia Penny, Anik Robitaille, Craig Siddall, Darlene Morrow, Iolanda Miller, Jane Mackay, and Marie Skelly at Jackie Gross & Associates for all their help and enthusiasm representing our product in Canada. Lois Fraser, Connie McMenemy, and the rest of the great folks at Jaguar Book Group for their help with distribution of Syngress books in Canada. Acknowledgments 167_C#_FM.qxd 12/5/01 10:16 AM Page v Contributors Todd Carrico (MCDBA, MCSE) is a Senior Database Engineer for Match.com. Match.com is a singles portal for the digital age. In addition to its primary Web site, Match.com provides back-end services to AOL, MSN, and many other Web sites in its affiliate program.Todd specializes in design and development of high-performance, high-availability data architectures primarily on the Microsoft technology. His background includes designing, developing, consulting, and project management for companies such as Fujitsu, Accenture, International Paper, and GroceryWorks.com. In addition to his contribution to C# .NET Web Developer’s Guide,Todd has also contributed chapters to other books in the Syngress .NET Series including the ASP .NET Web Developer’s Guide, and the VB .NET Developer’s Guide.Todd resides in Sachse,TX, with his wife and two children. Mark Tutt is a Senior Software Engineer with MICROS Systems. MICROS provides complete information management solutions for the hospitality industry, including software, hardware, enterprise systems integration, consulting, and support. Mark is the principle designer of a number of software packages, including Guest Service Solution, a customer relationship management system for the MICROS Restaurant Enterprise Series platform. In addition to his product development duties, Mark is a key contributor to the design and devel- opment of system integration software and customer-specific product exten- sions that allow MICROS clients to fully integrate MICROS products into their overall technology plans. Mark currently resides in Baltimore, Maryland with his wife Malinda and their twin sons, Fred and Jackson. Jason Werry (MCSD) runs a consulting firm, Synergy Data Solutions, in Australia. He currently provides strategic and technical consulting to his clients and specializes in Windows-based enterprise systems development. Jason has an extensive background using Microsoft technologies and is currently developing state-of-the-art,Web-based applications on the .NET platform. His clients have ranged from a Taiwanese multimedia company to various government depart- ments and local startups. A natural born programmer, Jason started coding Z80 processors in Assembly at age 13. Since then he has used most popular vi 167_C#_FM.qxd 12/5/01 10:16 AM Page vi vii programming languages and presently enjoys working with SQL Server, MTS, IIS,Visual Basic, and C#. Jason holds a bachelor’s degree in Mathematics/ Computer Science from The University of Queensland. He dedicates his writing to his loving wife, LiHsing. Patrick Coelho (MCP) is an Instructor at The University of Washington Extension, North Seattle Community College, Puget Sound Center, and Seattle Vocational Institute, where he teaches courses in Web Development (DHTML, ASP, XML, XSLT, C#, and ASP .NET). Patrick is a Co-Founder of DotThatCom.com, a company that provides consulting, online development resources, and internships for students. He is currently working on a .NET solution with contributing author David Jorgensen and nLogix. Patrick holds a Bachelor’s of Science degree from the University of Washington, Bothell. Patrick lives in Puyallup,WA with his wife Angela. David Jorgensen (MCP) is an Instructor at North Seattle Community College, University of Washington extension campus, and Puget Sound Centers. He is also developing courses for Seattle Vocational Institute, which teaches .NET and Web development to the underprivileged in the Seattle area. David also provides internship opportunities through his company DotThatCom.com, which does online sample classes and chapters of books. David holds a bach- elor’s degree in Computer Science from St. Martin’s College and resides in Puyallup,WA with his wife Lisa and their two sons Scott and Jacob. Greg Hack is a Senior Software Engineer with Allscripts Healthcare Solutions. Greg has over 15 years experience developing software on platforms ranging from the mainframe to the desktop using a wide variety of languages and tech- nologies. Recent work includes a Web-based application that allows patients to view their medical records and a Pocket PC application that delivers clinical information to physicians at the point of care. Axel Goldbach is a Senior Consultant with modulo3 GmbH, a consulting company based in Germany and specializing in project management consulting throughout Europe. modulo3 is a process implementation specialist for the major networking frameworks, including eXtreme Programming, MSF and V Modell. Axel currently provides senior-level strategic and technical consulting to all modulo3 clients in Germany and Central Europe. His duties include anal- ysis and development of multi-tiered applications in heterogeneous environments. 167_C#_FM.qxd 12/5/01 10:16 AM Page vii viii Axel also works as a technical scout and trainer for modulo3. His training spe- cialties include programming languages, networking, and academic fields such as development methodology, parser- and interpreter-technology, theory of com- plexity, and provable correct software. Joseph Albahari is a freelance consultant and developer with over 10 years experience in designing networked systems. He has led a string of successful projects, from custom application frameworks for start-up companies, to high- performance OLAP and data warehousing systems for telecommunications giants. His knowledge in object-oriented user interface design has been called upon in the planning or production of many large and complex systems, where well-balanced abstractions are of key importance. Joseph is also experienced in SQL Server database administration, and has developed high-performance solu- tions for clients with specialized requirements—such as a replication system providing field level synchronization, or a high-throughput bulk-copying agent. Joseph holds a Bachelor’s degree in computer science and physics. Adrian Turtschi (MCSE, MCSD) is Lead Architect Solution Development with Avanade (Germany), where he is responsible for the solution offering in the mobile computing space. He has been working on the Microsoft .NET platform since fall 2000, specializing in developing enterprise systems using Web Services. He is particularly interested in using Web Services to bridge platform and system boundaries. Prior to joining Avanade, Adrian worked for KPMG’s Global Knowledge Exchange in Boston, where he helped design and develop KPMG's global knowledge management and collaboration solution, used by its 100,000 professionals world-wide. Adrian has work experience in Switzerland, the Netherlands, and the US. He has degrees in Mathematics and Computer Science. He currently lives in Berlin, Germany. 167_C#_FM.qxd 12/5/01 10:16 AM Page viii ix Technical Editor and Reviewer Saurabh Nandu is the Founder of www.MasterCSharp.com which concen- trates on teaching C# and .NET. He worked with HTML, JavaScript, Flash 5.0 before he started programming in Java. Saurabh has been impressed by the power and flexibility of .NET. He is currently employed by YesSoftware Inc. as Technical Evangelist. Technical Editor’s Acknowledgements I would like to thank my friend Nanu Jogi without whose direction I would have never got into working on the .NET Platform. I would also like to thank my family, especially my brother Pritesh, for their support. Wei Meng Lee is Series Editor for Syngress Publishing’s .NET Developer Series. He is currently lecturing at The Center for Computer Studies, Ngee Ann Polytechnic, Singapore.Wei Meng is actively involved in Web development work and conducts training for Web developers and Visual Basic programmers. He has co-authored two books on WAP. He holds a Bachelor’s degree in Information Systems and Computer Science from the National University of Singapore.The first and second books of the .NET series, VB .NET Developer’s Guide (ISBN: 1-928994-48-2), and ASP .NET Developer’s Guide (ISBN: 1-928994-51-2) are currently available from Syngress Publishing. Series Editor 167_C#_FM.qxd 12/5/01 10:16 AM Page ix [...]... Writing a Custom Control Testing the Control Enhancing the Control Subclassing Controls xv 12 2 12 2 12 4 12 7 12 7 12 9 13 0 13 0 13 0 13 1 13 1 13 2 13 3 13 7 13 8 13 8 14 1 14 2 14 5 14 7 15 2 15 4 15 4 15 5 15 7 15 9 16 0 16 2 16 4 16 6 16 7 16 7 17 0 17 0 17 2 17 3 17 4 17 5 17 7 17 8 18 1 18 1 18 2 18 2 18 3 18 7 18 9 19 1 16 7_C#_TOC.qxd xvi 12 /5/ 01 11: 44 AM Page xvi Contents Custom Controls in Internet Explorer Setting Up IIS Creating a Virtual... 51 52 52 52 53 54 55 56 56 59 59 60 69 70 74 75 79 85 89 89 89 89 90 10 4 Chapter 3 Visual Studio.NET IDE 10 9 Introduction Introducing Visual Studio.NET Components of VS.NET Design Window Code Window Server Explorer Toolbox Docking Windows Properties Explorer Solution Explorer Object Browser Dynamic Help Task List Explorer 11 0 11 0 11 2 11 2 11 3 11 4 11 6 11 7 11 7 11 8 11 9 12 0 12 1 16 7_C#_TOC.qxd 12 /5/ 01 11: 44... Track/Frequently Asked Questions xxi 1 2 2 3 4 5 5 7 7 8 9 9 10 11 12 14 14 14 14 15 15 15 16 16 17 18 19 19 20 21 24 26 Chapter 2 Introducing C# Programming 33 Introduction Getting Started Creating Your First C# Program Compiling and Executing Defining a Class Declaring the Main Method Organizing Libraries with Namespaces 34 35 37 38 40 43 43 xiii 16 7_C#_TOC.qxd xiv 12 /5/ 01 11: 44 AM Page xiv Contents Using... Needed NET Classes A Web Access Client Compiling and Running the Example Request Method Redirection 19 3 19 3 19 3 19 4 19 6 203 204 204 206 208 211 212 213 214 216 217 220 226 227 228 229 2 31 234 235 236 240 243 250 250 253 256 260 260 265 268 269 2 71 272 276 279 283 283 284 285 289 290 290 16 7_C#_TOC.qxd 12 /5/ 01 11: 44 AM Page xvii Contents Authentication Cookies Summary/Solutions Fast Track/Frequently Asked... Formats Sending and Receiving Messages with Complex Objects Storing Files within Messages xvii 2 91 2 91 292 299 300 3 01 302 303 303 305 306 308 310 310 312 313 318 319 3 21 3 21 3 21 3 21 322 325 326 329 3 31 332 333 334 334 336 337 339 340 345 346 346 348 349 349 349 353 353 355 356 360 16 7_C#_TOC.qxd xviii 12 /5/ 01 11: 44 AM Page xviii Contents Setting Queue Options Creating a Complex Application Creating the... Working with Web Services Passing Complex Data Types Error Handling Malformed SOAP Request Wrong Argument Types Exceptions in Server Code 575 576 576 577 578 579 579 5 81 5 81 5 81 589 602 608 610 611 611 614 614 617 617 16 7_C#_TOC.qxd xx 12 /5/ 01 11: 44 AM Page xx Contents Writing a SOAP Client Application Passing Objects Passing Relational Data Passing XML Documents Working with UDDI SOAP Headers Advanced Web... 376 378 379 383 384 384 386 388 389 3 91 396 396 398 398 402 405 406 408 408 414 418 419 422 423 426 4 31 432 432 434 435 436 437 437 439 442 443 446 450 4 51 452 456 4 61 464 16 7_C#_TOC.qxd 12 /5/ 01 11: 44 AM Page xix Contents Working with XPath and XSL Transformations Working with XPath Working with XSL Summary/Solutions Fast Track/Frequently Asked Questions Chapter 10 ASP.NET xix 469 469 479 490 495 Introduction... 776 Index 7 81 167_C#_ 01. qxd 12 /3/ 01 5:42 PM Page 1 Chapter 1 Introducing the Microsoft NET Platform Solutions in this chapter: s Introducing the NET Platform s Features of the NET Platform s Components of the NET Architecture s Exploring the Code Cycle s The Pursuit of Standardization Summary Solutions Fast Track Frequently Asked Questions 1 167_C#_ 01. qxd 2 12 /3/ 01 5:42 PM Page 2 Chapter 1 • Introducing... handles all the work required when translating messages that pass back and forth between the managed runtime and the COM components operating as unmanaged code www.syngress.com 11 16 7_C#_ 01. qxd 12 12 /3/ 01 5:42 PM Page 12 Chapter 1 • Introducing the Microsoft NET Platform On the other side of the coin, companies with a vested interest in COM technology might want to use a few bits and pieces from the NET... easier, it is still frequently a monumental task to correctly install a retrievial application www.syngress.com 9 16 7_C#_ 01. qxd 10 12 /3/ 01 5:42 PM Page 10 Chapter 1 • Introducing the Microsoft NET Platform The NET design team must have felt the same way about this problem, because NET plans to do away with these issues for good .NET components are not referenced in the Registry, thanks to the use of . www.syngress.com/solutions 16 7_C#_FM.qxd 12 /5/ 01 10 :16 AM Page i 16 7_C#_FM.qxd 12 /5/ 01 10 :16 AM Page ii 1 YEAR UPGRADE BUYER PROTECTION PLAN Adrian Turtschi. Explorer 11 4 Toolbox 11 6 Docking Windows 11 7 Properties Explorer 11 7 Solution Explorer 11 8 Object Browser 11 9 Dynamic Help 12 0 Task List Explorer 12 1 16 7_C#_TOC.qxd