`
`Essentials
`
`O'REILLY®
`
`Thuan Thai & Hoang Q. Lam
`
`Ex.1015
`APPLE INC. / Page 1 of 25
`
`
`
`.NET Framework Essentials
`
`Ex.1015
`APPLE INC. / Page 2 of 25
`
`
`
`Other Microsoft .NET resources from O'Reilly
`
`Related titles
`
`Programming #
`C# in a utshell
`Programming Visual Basic
`. ET
`Programming A P.NET
`A P.NET in a Nutshell
`ADO. ET in a uc hell
`
`.NET Windows Forms in a
`ucshell
`Programming . ET Web
`ervices
`Mastering Visua l rudio
`.NE1
`Programming . ET
`Components
`
`.NET Books
`Resource Center
`
`'Reilly's
`dotnel.oreilly.com i a comp lete catalog of
`book
`n .NET and related rechn logies, including sam(cid:173)
`ple chapter and cod examples.
`
`O'REILLY'
`
`ONDotnet.com
`
`M'E('lfFJl#fTOT.7
`
`ONDotnel.com provides independent coverag
`interoperable, and emergi ng Micro
`m nm!,
`progr::imming and web services technologies.
`
`f funda(cid:173)
`ft .NET
`
`Conferences O'R illy & Associac s brings diver e innovacor cogerher ro
`nurture the ideas rhar spark revolutionary indu tri s. We
`specialize in docum ming the latest cools and systems,
`translating the inn vacor's know! dge into useful kills for
`those in che rrenchcs. Visit conferences. oreilly.com for our
`upcoming evem .
`
`f O'REIU.Y NETWORK
`
`Satari·
`ookshell.
`
`Safari Bookshelf (safari.oreilly.com) is the pr mier online
`reference library for programmer and IT pr f sionals.
`Conduce searches across more than 1,000 bo k . Sub(cid:173)
`scriber can zero in on answers co time-critical qu cions
`in a mauer of second . Read the books on your Book(cid:173)
`shelf fr m CO\ er co cover or simply flip to ch page you
`nee . Try it today with a free trial.
`
`Ex.1015
`APPLE INC. / Page 3 of 25
`
`
`
`.NET Framework Essentials
`
`THIRD EDITION
`
`Thuan Thai and Hoang Q, Lam
`
`O'REILLY.,
`Beijing • Cambridge • Farnham • Koln • Paris • Sebastopol • Taipei • Tokyo
`
`Ex.1015
`APPLE INC. / Page 4 of 25
`
`
`
`.NET Framework Essentials, Third Edition
`by Thuan Thai and Hoang Q. Lam
`
`Copyright© 2003, 2002, 2001 O'Reilly&: Associates, Inc. All rights reserved.
`Primed in the United States of America.
`
`Published by O'Reilly&: Associates, Inc., 1005 Gravenstein Highway North,
`Sebastopol, CA 95472.
`
`O'Reilly&: Associates books may be purchased for educational, business, or sales pro(cid:173)
`motional use. Online editions are also available for most titles (safari.oreilly.com). For
`more information, contact our corporate/institutional sales department: (800) 998-9938
`or corporate@oreilly.com.
`
`Editors:
`John Osborn and Valerie Quercia
`Production Editor: Matt Hutchinson
`Production Services: Octal Publishing, Inc.
`Cover Designer:
`Ellie Volckhausen
`Interior Designer:
`David Futato
`
`Printing History:
`June 2001:
`February 2002:
`August 2003:
`
`First Edition.
`Second Edition.
`Third Edition.
`
`Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered
`trademarks of O'Reilly&: Associates, Inc. Microsoft, MSDN, the .NET logo, Visual
`Basic, Visual C++, Visual Studio, and Windows are registered trademarks of Microsoft
`Corporation. Many of the designations used by manufacturers and sellers to distinguish
`their products are claimed as trademarks. Where those designations appear in this book,
`and O'Reilly&: Associates, Inc. was aware of a trademark claim, the designations have
`been printed in caps or initial caps. The association between the image of shrimp and
`the topic of the .NET Framework is a trademark of O'Reilly&: Associates, Inc.
`
`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.
`
`ISBN: 0-596-00505-9
`[M]
`
`Ex.1015
`APPLE INC. / Page 5 of 25
`
`
`
`Table of Contents
`
`Preface .......................................................... ix
`
`1.
`
`.NET Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
`2
`Behind Microsoft .NET
`3
`The .NET Platform
`4
`.NET Framework Design Goals
`9
`.NET Framework
`
`2. The Common Language Runtime ............................. 12
`CLR Environment
`12
`13
`CLR Executables
`19
`Meta data
`27
`Assemblies and Manifests
`34
`Intermediate Language (IL)
`The CTS and CLS
`37
`42
`CLR Execution
`47
`Summary
`
`3.
`
`.NET Programming ......................................... 49
`Common Programming Model
`49
`Core Features and Languages
`52
`Language Integration
`68
`Summary
`73
`
`4. Working with .NET Components .............................. 7 4
`Deployment Options
`7 4
`85
`Distributed Components
`
`V
`
`Ex.1015
`APPLE INC. / Page 6 of 25
`
`
`
`COM+ Services in .NET
`Message Queuing
`Summary
`
`89
`102
`106
`
`5. Data and XML ............................................. 107
`108
`ADO.NET Architecture
`109
`ADO.NET Benefits
`Content Components
`112
`126
`.NET Framework Data Providers
`XML in the .NET Framework
`138
`150
`Summary
`
`6. Web Services ............................................. 1 S1
`151
`Web Services in Practice
`153
`Web Services Framework
`164
`Web Services Provider
`170
`Web Services Consumers
`193
`Async Web Services
`197
`SOAP Header in Web Services
`200
`Web Services and Security
`202
`Summary
`
`7. ASP.NET .................................................. 204
`204
`ASP
`205
`ASP.NET
`206
`The System.Web.UI Namespace
`215
`Web Form Syntax
`223
`ASP.NET Application Development
`245
`ASP.NET and Web Services
`248
`Data Binding and the Use of Templates
`254
`State Management and Scalability
`260
`Forms Authentication in ASP.NET
`261
`Summary
`
`8. Windows Forms ........................................... 263
`263
`Introducing Windows Forms
`265
`The System.Windows.Forms Namespace
`269
`Windows Forms Development
`
`vi
`
`I Table of Contents
`
`Ex.1015
`APPLE INC. / Page 7 of 25
`
`
`
`Windows Forms and Web Services
`Summary
`
`296
`297
`
`9.
`
`.NET and Mobile Devices .................................... 298
`298
`ASP.NET Mobile Controls
`309
`.NET Compact Framework
`323
`Summary
`
`A.
`
`.NET Languages ........................................... 325
`
`B. Common Acronyms ........................................ 327
`
`C. Common Data Types ................. . ..................... 331
`
`D. Common Utilities ................... . ...................... 339
`
`Index .......................................................... 349
`
`Table of Contents
`
`I vii
`
`Ex.1015
`APPLE INC. / Page 8 of 25
`
`
`
`Preface
`
`A condensed introduction to the Microsoft .NET Framework, this book
`aims to help programmers make the transition from traditional Windows
`programming to the world of .NET programming. The Microsoft .NET
`Framework includes the Common Language Runtime (CLR) and a set of
`base classes that radically simplify the development of large-scale applica(cid:173)
`tions and services. This book examines the CLR in detail, so that you can
`put its new features to good use. The book also illustrates how language
`integration really works and guides you through component and enterprise
`development using the .NET Framework. In addition, it introduces you to
`four key .NET technologies: data (ADO.NET) and XML, web services, Web
`Forms (ASP.NET), and Windows Forms.
`
`We used the latest release of Microsoft Visual Studio .NET 2003 and the .NET
`Framework SOK 1.1 to prepare this manuscript and to develop all the exam(cid:173)
`ples and figures in this book. In .NET Framework SOK 1.1, Microsoft has fixed
`a number of bugs, made performance and security improvements, and added a
`few important changes, including:
`
`• Support for additional ADO.NET data sources (Oracle and ODBC)
`• Improved support for using C++ to build .NET Windows and Web
`applications
`• Integration of J# into VS.NET
`• Inclusion of a mobile controls package for developing ASP .NET sites for
`small devices, such as cell phones
`• Integration of mobile application development into VS.NET
`
`Although we have done our best to ensure that the technical content of this
`book is up-to-date, it is possible that some items have changed slightly from the
`time of writing. To stay up-to-date, regularly check http://msdn.microsoft.com/
`
`ix
`
`Ex.1015
`APPLE INC. / Page 9 of 25
`
`
`
`net, http://www.gotdotnet.com, and this book's O'Reilly page, http://www.
`oreilly.comlcatalog!dotnetfrmess3/.
`
`Audience
`Although this book is for any person interested in learning about the
`Microsoft .NET Framework, it targets seasoned developers with experience
`in building Windows applications with Visual Studio 6 and the Visual Basic
`and Visual C++ languages. Java™ and CIC++ developers will also be well
`prepared for the material presented here. To gain the most from this book,
`you should have experience in object-oriented, component, enterprise, and
`web application development. COM programming experience is a plus.
`
`About This Book
`Based on a short course that Thuan has delivered to numerous companies
`since August 2000, this book is designed so that each chapter builds on
`knowledge from the previous one for those unfamiliar with each technol(cid:173)
`ogy. To give you a heads-up, here are brief summaries for the chapters and
`appendixes covered in this book.
`Chapter 1, .NET Overview, takes a brief look at Microsoft .NET and the
`Microsoft .NET Platform. It then describes the .NET Framework design
`goals and introduces you to the components of the .NET Framework.
`Chapter 2, The Common Language Runtime, lifts the hood and peers into
`the CLR. This chapter surveys the rich runtime of the CLR, as well as other
`features.
`Chapter 3, .NET Programming, introduces you to .NET programming.
`You'll examine a simple program that uses object-oriented and component(cid:173)
`based concepts in five different languages: Managed C++, VB.NET, C#, J#,
`and IL. You'll also experience the benefits oflanguage integration.
`Chapter 4, Working with .NET Components, demonstrates the simplicity
`of component and enterprise development in .NET. Besides seeing the
`component-deployment features of the .NET Framework, you'll also find
`complete programs that take advantage of transaction, object pooling,
`role-base security, and message queuing-all in one chapter.
`Chapter 5, Data and XML, describes the architecture of ADO.NET and its
`benefits. Besides being disconnected to promote scalability, the ADO.NET
`dataset is also tightly integrated with XML to enhance interoperability. This
`
`x I Preface
`
`Ex.1015
`APPLE INC. / Page 10 of 25
`
`
`
`chapter introduces you to the .NET data-access objects, as well as the XML
`namespace.
`Chapter 6, Web Services, describes how .NET software components can be
`accessed through the Internet. In this chapter, we discuss the protocols that
`support web services, as well as how to publish and discover them. You will
`see how XML, used in conjunction with HTTP, breaks the proprietary
`nature of typical component-oriented software development and enables
`greater interoperability.
`Chapter 7, ASP.NET, introduces you to ASP .NET, which now supports
`object-oriented and event-driven programming, as opposed to conventional
`ASP development. In this chapter, Web Forms and server controls take the
`center stage. In addition, we examine how to build custom server controls,
`perform data· binding to various .NET controls, and survey state manage(cid:173)
`ment features in ASP.NET.
`Chapter 8, Windows Forms, takes conventional form-based programming a
`step into the future with the classes in the System.Windows.Forms
`namespace. Similar to Win32-based applications, Windows Forms are best
`used to build so-called rich or "fat" clients; however, with the new zero(cid:173)
`effort installation procedure of .NET and the advent of web services, Win(cid:173)
`dows Forms are appropriate for a host of applications.
`Chapter 9, .NET and Mobile Devices, shows you how to build an ASP.NET
`application that targets smart devices and a mobile device application that is
`backed by SQL Server CE.
`Appendix A, .NET Languages, contains a list of links to web sites with infor(cid:173)
`mation regarding languages that target the CLR, including some burgeoning
`open-source projects.
`Appendix B, Common Acronyms, contains a list of commonly used acro(cid:173)
`nyms found in .NET literature and presentations.
`Appendix C, Common Data Types, contains several lists of commonly used
`data types in .NET. This appendix also illustrates the use of several .NET
`collection classes.
`Appendix D, Common Utilities, surveys the important tools that the .NET
`SDK provides to ease the tasks of .NET development.
`
`Assumptions This Book Makes
`This book assumes that you are a Windows or web application developer
`fluent in object-oriented and component-based programming. We also
`
`Preface
`
`I xi
`
`Ex.1015
`APPLE INC. / Page 11 of 25
`
`
`
`assume that you have some basic knowledge of XML. While COM is not a
`crucial prerequisite, if you have COM programming experience, you will
`appreciate this book and the .NET Framework all the more.
`
`Conventions Used in This Book
`We use the following font conventions in this book.
`Italic is used for:
`
`• Pathnames, filenames, and program names
`• Internet addresses, such as domain names and URLs
`• New terms where they are defined
`
`Constant width is used for:
`
`• Command lines and options that should be typed verbatim
`• Direct quotes and specific method names from code examples, as well
`as specific values for attributes and settings within code
`• XML element tags
`Constant width bold is used for:
`
`• User input in code that should be typed verbatim
`• Items in code to which we,d like to draw the reader's attention
`
`Constant width italic is used for:
`
`• Replaceable items in code, which should be replaced with the appropri-
`ate terms
`
`In code syntax examples, we sometimes use [value]+ to represent one or
`more instances of a value and [value]* to mean zero or more instances of a
`value.
`.. '
`
`This icon designates a tip, which contains imponant infor-
`mation about the nearby text.
`
`~,·
`'
`'-------'~~·
`
`.. ,
`
`This icon designates a warning related to the nearby text.
`
`xii
`
`I Preface
`
`Ex.1015
`APPLE INC. / Page 12 of 25
`
`
`
`How to Contact Us
`We have tested and verified the information in this book to the best of our
`abilities, but you may find that features have changed (or even that we have
`made mistakes!). Please let us know about any errors you find, as well as
`your suggestions for future editions, by writing to:
`
`0 'Reilly &: Associates, Inc.
`1005 Gravenstein Highway North
`Sebastopol, CA 954 72
`(800) 998-9938 (in the United States or Canada)
`(707) 829-0515 (international/local)
`(707) 829-0104 (FAX)
`
`You can also send us messages electronically. To be put on the mailing list
`or request a catalog, send email to:
`info@oreilly.com
`To ask technical questions or comment on the book, send email to:
`bookquestions@oreilly.com
`We have a web site for the book, where we list examples, errata, and any
`plans for future editions. You can access this page at:
`http://www.oreilly.com/catalog/dotnetfrmess3/
`For more information about this book and others, see the O'Reilly web site:
`http://www.oreilly.com
`For more information on .NET in general, visit the O'Reilly .NET Center at
`http://dotnet.oreilly.com and the .NET DevCenter at http://www.oreillynet.com/
`dotnetl.
`
`Acknowledgments
`The folks at O'Reilly never cease to amaze us with the support that they pro(cid:173)
`vide. We'd like to thank O'Reilly executive editor John Osborn for extend(cid:173)
`ing us the contract to write this book and for his continuous support
`throughout the project. Thanks to O'Reilly editor Nancy Kotary for making
`the first and second editions of this book such a success. We'd also like to
`thank O'Reilly editor Valerie Quercia who did a fine job reviewing our mate(cid:173)
`rials and coordinating the project for this third edition.
`
`Preface
`
`I xiii
`
`Ex.1015
`APPLE INC. / Page 13 of 25
`
`
`
`We'd like to give many thanks to the production and design folks at
`O'Reilly for making this book a reality: Emma Colby, David Futato, Matt
`Hutchinson, Robert Romano, and Ellie Volckhausen.
`
`We'd like to thank Brian Jepson, who has contributed significantly to this
`book since the beginning of the project. Brian did an unquestionably out(cid:173)
`standing job reading, testing, and ensuring that the technical content in
`every chapter lined up with the latest release. He also gave us invaluable
`guidance and support throughout the project. We'd like to thank Matthew
`MacDonald for the same reason, since he's been providing invaluable feed(cid:173)
`back and recommendations in the third edition. We'd also like to thank
`Dennis Angeline and Brad Merrill at Microsoft for answering technical ques(cid:173)
`tions on the CLR and languages.
`
`Thuan Thai
`I would like to thank my parents, siblings, and Ut Nga for their constant
`support during this project.
`
`Hoang Q. Lam
`I would like to thank my parents and family for their support and under(cid:173)
`standing of my being missing-in-action for several months. Mom and Dad,
`your ongoing efforts to put your children where they are today can never be
`repaid.
`
`I would like to thank my wife, Van Du, and daughter, Nina. Your smiles
`mean the world to me. Don't underestimate your contribution to this book.
`
`xiv
`
`I Preface
`
`Ex.1015
`APPLE INC. / Page 14 of 25
`
`
`
`CHAPTER 1
`.NET Overview
`
`The .NET Framework is a development framework that provides a new pro(cid:173)
`gramming interface to Windows services and APis, and integrates a number
`of technologies that emerged from Microsoft during the late 1990s.
`Microsoft announced the .NET initiative in July 2000. In April 2003, Ver(cid:173)
`sion 1.1 of the integral .NET Framework was released. This book describes
`this updated version of the .NET Framework.
`
`The .NET platform consists of four separate product groups:
`Development tools and libraries
`A set of languages, including C#, J#, and VB.NET; a set of develop(cid:173)
`ment tools, including Visual Studio .NET; a comprehensive class library
`for building web services and web and Windows applications; as well as
`the Common Language Runtime (CLR). These components collectively
`form the largest part of the .NET Framework.
`Web services
`An offering of commercial web services, specifically the .NET Services
`initiative; for a fee, developers can use these services in building applica(cid:173)
`tions that require them.
`Specialized servers
`A set of .NET-enabled enterprise servers, including SQL Server,
`Exchange Server, BizTalk Server, and so on. These provide specialized
`functionality for relational data storage, email, and B2B commerce.
`Future versions of these products will increasingly support the .NET
`Framework.
`Devices
`New .NET-enabled, non-PC devices, from cell phones to game boxes.
`
`1
`
`Ex.1015
`APPLE INC. / Page 15 of 25
`
`
`
`Behind Microsoft .NET
`While the main strategy of .NET is to enable software as a service, .NET is
`much more than that. In addition to embracing the Web, Microsoft .NET
`acknowledges and responds to the following trends within the software
`industry:
`Distributed computing
`Simplifies the development of robust client/server and multi-tier (n-tier)
`applications. Traditional distributed technologies require high vendor(cid:173)
`affinity and are unable to interoperate with the Web. Microsoft .NET
`provides remoting and web services architectures that exploit open
`Internet standards, including the Hypertext Transfer Protocol (HTTP),
`Extensible Markup Language (XML), and Simple Object Access Proto(cid:173)
`col (SOAP) and WSOL.
`Componentization
`Simplifies the integration of software components developed by differ(cid:173)
`ent vendors and supports development of distributed applications. The
`Component Object Model (COM) has brought reality to software plug(cid:173)
`and-play, but COM component development and deployment are too
`complex. Microsoft .NET provides a simpler way to build and deploy
`components.
`Enterprise services
`Allow the development of scalable enterprise applications without writ(cid:173)
`ing code to manage transactions, security, or pooling. Microsoft .NET
`continues to support COM and component services, since these ser(cid:173)
`vices greatly reduce the development time and effort required to build
`large-scale applications.
`Web paradigm shifts
`Over the past decade, web application development has shifted from
`connectivity (TCP/IP), to presentation (HTML), to programmability
`(XML and SOAP). A key goal of Microsoft .NET is to enable the shar(cid:173)
`ing of functionality across the Web among different platforms, devices,
`and programming languages.
`Maturity of IT industry
`Lessons that the software industry has learned from developing large(cid:173)
`scale enterprise and web applications. A commercial web application
`must support interoperability, scalability, availability, security, and
`manageability. Microsoft .NET facilitates all these goals.
`
`Although these are the sources of many ideas embodied by Microsoft .NET,
`what's most notable about the platform is its use of open Internet standards
`
`2 I Chapter 1: .NET Overview
`
`Ex.1015
`APPLE INC. / Page 16 of 25
`
`
`
`(HTTP, XML, and SOAP) at its core to tran mit information from on
`Internet. In fact, .NET provides bidirectional
`machine to an ther across th
`mapping b tween XML and objects . For exampl , a cla
`ca n be expr s ed
`as an XML Sch ma Definition (XSD) ; an object can be converted co and
`from an X lL buffer· a method can be specified u ing an XML format called
`Web Servic De crip tion Languag
`(WSDL); and a method call can be
`expressed u ing an XML format call d SOAP.
`
`The . NET Platform
`The 1icrosoft . ET platform consi t of five main c mponents, as hown
`in Figur 1-1. At the !owe t layer lies the operating ys tem (OS), which can
`be one of a variety of Window platforms, including W indows XP, Win(cid:173)
`dows 2000, Windows Server 2003, Windows ME, and Windows CE . As
`part of th e .NET strategy, Microsoft has promis d t deliver mor
`.NET
`device software to facilitate a new gen ration of smart d vices.
`
`Visual Studio .NET
`
`.NET Enterprise
`Servers
`
`.NET Framework
`
`.NET Building
`Block Services
`
`Operating system on servers, desktops, and devices
`
`Figure 1-1 . Th e Microsoft .NET platform
`
`On top of the opera ting system is a collection of pecialized server products
`that shortens the time required to develop large- cal business sy t ms.
`These server products include Applica ti on Center, BizTalk Server, Com(cid:173)
`merce Server Exchange Server Ho t Integration Server, Internet Security
`and Acceleration Server, and SQL Server.
`
`Since web service are highly reusable across th e Web,
`a
`licrosoft pr vid
`number of building-block services (officially called .NET Services) that
`applications developers can u e, for a fee. Two examples of .NET S rvice
`that Microsoft offers includ
`. ET Passport and . ET Al res. . ET Pa s(cid:173)
`port allows you to use a single username and pa word at all web site chat
`support Pa port authentication. . ET Alerts all ow .1 ET Alert provider
`such as a bu ine
`, to alert their con umers with important or up-co-the(cid:173)
`minute information. Microsoft plans to add newer ervices, such a cal n(cid:173)
`dar, direc tory, an d search services. Third-party v ndors are also creating
`new web services of their own.
`
`The .NET Platform
`
`I 3
`
`Ex.1015
`APPLE INC. / Page 17 of 25
`
`
`
`The top layer of the .NET architecture is a development tool called Visual
`Studio .NET (VS.NET), which makes possible the rapid development of
`web services and other applications. A successor to Microsoft Visual Studio
`6.0, VS.NET is an Integrated Development Environment (IDE) that sup(cid:173)
`ports four different languages and features such as cross-language debug(cid:173)
`ging and the XML Schema Editor.
`
`And at the center of .NET is the Microsoft .NET Framework-the main
`focus of this book. The .NET Framework is a development and runtime
`infrastructure that c;hanges the development of business applications on the
`Windows platform. The .NET Framework includes the CLR and a common
`framework of classes that can be used by all .NET languages .
`
`. NET Framework Design Goals
`The Microsoft .NET Framework embodies design goals that are both practi(cid:173)
`cal and ambitious. In this section, we discuss the main design goals of the
`Microsoft .NET Framework, including support for components, language
`integration, application interoperation across the Web, simplified develop(cid:173)
`ment and deployment, improved reliability, and greater security.
`
`Component Infrastructure
`Prior to the introduction of COM technology, developers had no standard
`way to integrate binary libraries without referring to or altering their source
`code. With the advent of COM, programmers were able to integrate binary
`components into their applications, similar to the way we can plug-and-play
`hardware components into our desktop PCs. Although COM was great, the
`grungy details of COM gave developers and administrators many headaches.
`
`Although COM permits you to integrate binary components developed
`using any language, it does require you to obey the COM identity, lifetime,
`and binary layout rules. You must also write the plumbing code that is
`required to create a COM component, such as DllGetClassObject, CoRegister(cid:173)
`ClassObject, and others.
`
`Realizing that these requirements result in frequent rewrites of similar code,
`.NET sets out to remove them. In the .NET world, all classes are ready to be
`reused at the binary level. You don't have to write extra plumbing code to
`support componentization in the .NET Framework. You simply write a .NET
`class, which then becomes a part of an assembly (to be discussed in
`Chapter 2) that inherently supports plug-and-play.
`
`4 I Chapter1: .NETOverview
`
`Ex.1015
`APPLE INC. / Page 18 of 25
`
`
`
`In addition to providing a framework to make development easier, .NET
`removes the pain of developing COM components. Specifically, .NET removes
`the use of the registry for component registration and eliminates the require(cid:173)
`ments for extraneous plumbing code found in all COM components, including
`code to support !Unknown, class factories, component lifetime, registration,
`dynamic binding, and others.
`
`fl .. ,
`"Component" is a nasty word because one person may use it
`· •'
`to refer to an object and another may use it to refer to a com-
`~~·
`.___' ~:.• piled binary module. To be consistent, this book uses the
`• term "COM component" (or simply "component") to refer
`to a binary module, such as a DLL or an EXE.
`
`Language Integration
`COM supports language independence, which means that you can develop a
`COM component in any language you want. As long as your component
`meets all the rules spelled out in the COM specification, it can be instanti(cid:173)
`ated and used by your applications. Although this supports binary reuse, it
`doesn't support language integration. In other words, you can't reuse the
`code in the COM components written by someone else; you can't extend a
`class hosted in the COM component; you can't catch exceptions thrown by
`code in the COM component; and so forth.
`
`Microsoft .NET supports not only language independence, but also lan(cid:173)
`guage integration. This means that you can inherit from classes, catch
`exceptions, and take advantage of polymorphism across different lan(cid:173)
`guages. The .NET Framework makes this possible with a specification
`called the Common Type System (CTS), which all .NET components must
`support. For example, everything in .NET is an object of a specific class that
`derives from the root class called System.Object. The CTS supports the gen(cid:173)
`eral concepts of classes, interfaces, delegates (which support callbacks), ref(cid:173)
`erence types, and value types. The . NET base classes provide most of the
`base system types, such as those that support integer, string, and file manip(cid:173)
`ulation. Because every language compiler must meet a minimum set of rules
`stipulated by the Common Language Specification (CLS) and generate code
`to conform to the CTS, different .NET languages can be used in the same
`application. We will examine the CTS and CLS in Chapter 2.
`
`Internet Interoperation
`COM supports distributed computing through its Distributed COM (DCOM)
`wire protocol. A problem with DCOM is that it embeds the host TCP/IP
`
`.NET Framework Design Goals
`
`I S
`
`Ex.1015
`APPLE INC. / Page 19 of 25
`
`
`
`address inside the Network Data Representation (NDR) buffer, such that it
`will not work through firewalls and Network Address Translation (NAT)
`software. In addition, the DCOM dynamic activation, protocol negotiation,
`and garbage collection facilities are proprietary, complex, and expensive.
`The solution is an open, simple, and lightweight protocol for distributed
`computing. The .NET Framework uses the industry-supported SOAP proto(cid:173)
`col, which is based on the widely accepted XML standards.
`
`Simplified Development
`If you have developed software for the Windows platforms since their incep(cid:173)
`tion, you have seen everything from the Windows APis to the Microsoft
`Foundation Classes (MFC), the Active Template Library (ATL), the system
`COM interfaces, and countless other environments, such as Visual Interdev,
`Visual Basic, ]Script, and other scripting languages. Each time you set out to
`develop something in a different compiler, you had to learn a new API or a
`class library, because there is no consistency or commonality among these
`different libraries or interfaces .
`
`. NET solves this problem by providing a set of framework classes that every
`language uses. Such a framework removes the need for learning a new API
`each time you switch languages.
`
`Simplified Deployment
`Imagine this scenario: your Windows application, which uses three shared
`Dynamic Link Libraries (DLLs), works just fine for months, but stops work(cid:173)
`ing one day after you've installed another software package that overwrites
`the first DLL, does nothing to the second DLL, and adds an additional copy
`of the third DLL into a different directory. If you have ever encountered
`such a brutal-yet entirely possible-problem, you have entered DLL Hell.
`And if you ask a group of seasoned developers whether they have experi(cid:173)
`enced DLL Hell, they will grimace at you in disgust, not because of the ques(cid:173)
`tion you've posed, but because they have indeed experienced the pain and
`suffering.
`
`To avoid DLL Hell on Windows 2000 and subsequent Windows operating
`systems (at least for system DLLs), Windows 2000 stores system DLLs in a
`cache. If you install an application that overwrites system DLLs, Windows
`2000 will overwrite the added system DLLs with the original versions from
`the cache.
`
`Microsoft .NET further diminishes DLL Hell. In the .NET environment,
`your executable will use the shared DLL with which it was built. This is
`
`6 I Chapter 1: .NET Overview
`
`Ex.1015
`APPLE INC. / Page 20 of 25
`
`
`
`guaranteed, because a shared DLL must be registered against something
`similar to the Windows 2000 cache, called the Global Assembly Cache
`(GAC). In addition to this requirement, a shared DLL must have a unique
`hash value, public key, locale, and version number. Once you've met these
`requirements and registered your shared DLL in the GAC, its physical file(cid:173)
`name is no longer important. In other words, if you have two versions of a
`DLL that are both called MyDll.dll, both of them can live and execute on the
`same system without causing DLL Hell. This is possible because the execut(cid:173)
`able that uses one of these DLLs is tightly bound to a specific version of the
`DLL during compilation.
`
`In addition to eradicating DLL Hell, .NET also removes the need for
`component-related registry settings. A COM developer will tell you that half
`the challenge of learning COM is understanding the COM-specific registry
`entries for which the developer is responsible. Microsoft .NET stores all ref(cid:173)
`erences and dependencies of .NET assemblies within a special section called
`a manifest (see Chapter 2). In addition, assemblies can be either private or
`shared. Private assemblies are found using logical paths or XML-based
`application configuration files, and public assemblies are registered in the
`GAC; in both cases, the system will find your dependencies at runtime. If
`they are missing, you get an exception telling you exactly what happened.
`
`Finally, .NET brings back the concept of zero-impact installation and
`removal. This concept is the opposite of what you have to deal with in the
`world of CO