Introduction

Yes, it’s that time again—time to throw away everything you know and start all over. The era of Microsoft .NET has arrived, and with it comes a promise to change software development as we know it. Microsoft .NET is many things, but first and foremost it’s a better way to write software in an Internet-centric world. To benefit from .NET, you’ll find it helpful to let go of any preconceived notions and prepare yourself to think about software in a whole new light. That means shedding comfortable clothing such as the Windows API, MFC, and COM, and immersing yourself in new ways of developing and architecting software that are unlike anything you’ve seen before.

When I began writing this book in July 2001, I had been working with the .NET Framework SDK for more than a year. The .NET Framework was in beta at the time and was still months away from emerging as a released product. When I first laid eyes on it, I expected to see something that resembled COM. What I saw instead was a radical departure from anything Microsoft had done before and a better way to write software. If your company’s plans include Web apps, Web services, or other applications that use the Internet as their platform, there simply is no better way to write those applications than to use Microsoft .NET. I would no more consider writing a Web app today with ASP than I would consider using a wrench to drive nails. The first ingredient for a successful software project is picking the right tool for the job. If your job involves Web programming (and maybe even if it doesn’t), Microsoft .NET is just the tool that you need.

This book is about Microsoft .NET—what it is, how it works, and how to write software that uses it. Among other things, you’ll learn about the common language runtime (CLR) and the highly structured environment that it provides for executing code compiled from C#, Visual Basic .NET, and other languages. You’ll learn about the .NET Framework class library (FCL), the stunningly comprehensive class library that provides the API managed applications write to. You’ll become acquainted with the programming models embodied in the FCL, including Windows Forms, Web Forms, and XML Web services. And just as important, you’ll learn how to make all the pieces work together to write sophisticated applications that leverage the power of Microsoft .NET.

The Journey Ahead

Programming Microsoft .NET tells a story—the story of Microsoft .NET. You can read it from beginning to end and learn in step-wise fashion how to write software that targets the .NET Framework. The book is also structured so that individual chapters stand alone. If you’re a seasoned .NET developer who simply wants to learn about multithreading, turn to Chapter 14 for a detailed treatment of threads and thread synchronization. If it’s custom ASP.NET server controls that float your boat, go straight to Chapter 8. The information you find there will help you get the job done with a minimum of wasted motion.

If you prefer the beginning-to-end approach, here’s what you’ll encounter along the way. Part I of this book builds the foundation you need for understanding and profiting from subsequent chapters. You’ll become acquainted with the Microsoft .NET Framework, which includes the common language runtime and the .NET Framework class library. You’ll learn about the framework’s type system and about some of the more than 7,000 types included in the FCL. You’ll also learn about one of the .NET Framework’s most important programming models: Windows Forms. Windows Forms lets you build GUI applications similar to the ones that are so prevalent in Windows today. Later on, in Chapter 15, you’ll even learn how to pair Windows Forms with the .NET Framework’s remoting subsystem to build rich client apps that link to remote servers.

Part II is all about ASP.NET—the portion of the .NET Framework that helps you build Web applications and Web services. Web programming today is a black art built around HTML, DHTML, ASP, COM, and other loosely related technologies. Web programming tomorrow will be a science, thanks to ASP.NET. If you’ve tried Web programming before and don’t like it because you don’t like dealing with slow, weakly typed scripting languages and find browser DOMs more trouble than they’re worth, ASP.NET might just change your mind. It’s a true second-generation technology for building applications that run on the Web. Moreover, it brings compiled code, strong type safety, and (to a degree) browser independence to Web programming. Chapter 5 through Chapter 11 cover ASP.NET in detail and impart the skills you need to write cutting-edge ASP.NET Web applications and Web services.

Part III rounds out the book with detailed coverage of selected portions of the .NET Framework. Topics include ADO.NET, which provides a database access API for managed applications; XML and all the classes that the FCL provides for dealing with XML data; threading, or how to write multithreaded code and coordinate the actions of concurrently running threads; and remoting, which provides a framework for writing closely coupled distributed applications. Take these chapters to heart and you’ll be able to hold your own in conversations at .NET parties.

A Word About Programming Languages

One of the hallmarks of the .NET Framework is that it is language-agnostic. For the first time in history, it matters little what language you choose to write code in because in the end all languages exercise the same set of features in the .NET Framework.

I do all my coding in C#, in part because C# is the only language designed specifically with the .NET Framework in mind, and also, because I’m an old C++ guy, C# feels natural to me. Since I’m a C# programmer, the vast majority of the code samples in this book are written in C#, too. Few of the concepts presented in the book, however, relate only to C#. This book is about programming the .NET Framework, and C# happens to be the vehicle that I use to express my thoughts. If you prefer Visual Basic .NET or COBOL instead, it is my hope that this book will be no less valuable to you. Once you know how to open a connection to a database with ADO.NET, the code for actually doing it is remarkably similar whether it’s written in Visual Basic .NET or C#.

Most of the samples in this book were written by hand, without the help of Visual Studio .NET. That’s not a knock on Visual Studio .NET; it’s evidence of my belief that learning is best accomplished by coding and not by having someone else code for you. Once you understand what goes into a Windows form or a Web form or a Web service, you’ll find Visual Studio .NET an able partner in helping to create them. Writing applications the old-fashioned way first will increase your depth of understanding and better prepare you to work in an environment in which tools shoulder part of the load for you.

System Requirements

To compile and run the more than 75 sample programs included in this book, you must have the .NET Framework Software Development Kit (SDK) installed on your machine. The SDK runs on Windows NT 4.0, Windows 2000, Windows XP, and presumably on later versions of Windows as well. The CD that comes with this book includes version 1.0 of the .NET Framework SDK as well as Service Pack 1. When newer versions become available, you can download them by pointing your browser to http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml. We all know that URLs change. If you go to this one and find that it’s no longer valid, visit the Microsoft .NET home page at http://www.microsoft.com/net for the latest information on where to find the SDK.

Chapter 5 through Chapter 11 of this book, which cover ASP.NET, impose another requirement on your system. In addition to being outfitted with the .NET Framework SDK, your PC needs to have Microsoft’s Web server, Internet Information Services (IIS), installed. Because ASP.NET requires Windows 2000 or Windows XP, you need one of those operating systems, too. On the Professional editions of these operating systems, IIS isn’t part of the default installation. To install IIS, open Add or Remove Programs in Control Panel and select Add/Remove Windows Components. You’ll find a check box for IIS. Be sure to install IIS before installing the SDK to make sure ASP.NET gets installed, too.

Some of the chapters in this book include sample programs built with Visual Studio .NET and provide Visual Studio .NET–specific instructions. You don’t have to have Visual Studio .NET to build code that targets the .NET Framework; the SDK comes with command-line compilers. However, Visual Studio .NET offers a highly integrated development environment that makes writing, testing, and debugging code easier. If you don’t already own a copy of Visual Studio .NET, you can purchase one from Microsoft. For more information, visit http://msdn.microsoft.com/vstudio/howtobuy.

What’s on the CD

Programmers like goodies. The CD that comes with this book contains the following delectable delights:

  • All of the book’s sample programs, source code included

  • A fully searchable electronic version of the book

  • The .NET Framework SDK version 1.0 and Service Pack 1

You’ll find instructions on the CD for installing the components that come on it. If AutoPlay is enabled on your PC, simply pop the CD in a drive to get started. In addition to being included on the CD, the sample files are available for download from http://www.microsoft.com/mspress/books/5200.asp.

Support

If you have comments about this book, questions you want answered, or errors to report, please post them at http://forum.wintellect.com/pro_ms_net. I’ll check the message board regularly and do my best to respond. Others will monitor message traffic also and jump in as appropriate. If you have a question, chances are someone else has one just like it. The answer may already be posted. If not, by posting your question in a public forum, you enable others to benefit from the answer as well.

I’d like to tell you that this book contains no errors, but of course I’d be lying. I’ve done everything humanly possible to verify the accuracy of every sentence and every code sample, but errors will inevitably surface. You’ll find an up-to-date errata list at http://www.wintellect.com/about/instructors/prosise/netbook.asp. If you don’t want to fuss with a long URL, simply go to http://www.prosise.com, and you’ll find a link there.

If you’d like to contact Microsoft Press directly about this book or need to resolve packaging problems (such as a defective or missing CD), you can contact them on line at http://www.microsoft.com/mspress/support. If you prefer paper mail, the address is:

Microsoft Press

Attn: Programming Microsoft .NET Editor

One Microsoft Way

Redmond, WA 98052-6399

Blogs and Other Things That Go Bump in the Night

Ever wonder what it’s like to write a book? When I wrote my first one in 1990, I learned that writing a book is an emotional roller coaster filled with peaks and valleys. The peaks are the elation that you feel when you describe a complex technical topic in a way that lifts the veil so that others can understand. The valleys come from thinking of the sheer magnitude of the effort that lies before you. Many is the time I wish I had kept a diary of that period in my life. Although I vividly remember the incredible relief I felt when I packaged up the last chapter and dropped it into a Fedex box (publishers still required printed manuscripts in those days), most of the day-to-day details of that experience escape me.

That’s why I documented my experience writing Programming Microsoft .NET in my very own book blog. “Blog” is short for “Web log”; it’s a diary published on the Internet. People all over the world tracked my progress as I wrote this book by checking my (almost) daily blog entries. If you’d like to relive the experience, you’ll find the finished blog at http://www.wintellect.com/about/instructors/prosise/blog.

Finally, a personal note. There’s no shortage of Microsoft .NET programming books on the market. I’m humbled that you chose this one, and I sincerely hope your investment in this book pays for itself many times over. Enjoy!

Jeff Prosise

March 13, 2002

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.153.212