Table of Contents
| Ch. 1 | What is Microsoft .NET? | 9 |
| Ch. 2 | Introducing VB.NET and VS.NET | 27 |
| Ch. 3 | The common language runtime | 59 |
| Ch. 4 | Variables and type | 81 |
| Ch. 5 | Object syntax introduction | 111 |
| Ch. 6 | Inheritance and interfaces | 163 |
| Ch. 7 | Applying objects and components | 221 |
| Ch. 8 | Namespaces | 255 |
| Ch. 9 | Error handling | 271 |
| Ch. 10 | Using XML in VB.NET | 301 |
| Ch. 11 | Data access with ADO.NET | 349 |
| Ch. 12 | Windows forms | 395 |
| Ch. 13 | Creating windows controls | 443 |
| Ch. 14 | Web forms | 479 |
| Ch. 15 | Creating web controls | 523 |
| Ch. 16 | Data binding | 583 |
| Ch. 17 | Working with classic COM and interfaces | 613 |
| Ch. 18 | Component services | 639 |
| Ch. 19 | Threading | 671 |
| Ch. 20 | Remoting | 719 |
| Ch. 21 | Windows services | 749 |
| Ch. 22 | Web services | 781 |
| Ch. 23 | VB.NET and the Internet | 813 |
| Ch. 24 | Security in the .NET framework | 847 |
| Ch. 25 | Assemblies and deployment | 897 |
| Ch. 26 | Mobile application development | 957 |
| App. A | Upgrading : using the Visual Basic compatibility library | 985 |
Read a Sample Chapter
Professional VB.NET 2003
By Bill Evjen Billy Hollis Rockford Lhotka Tim McCarthy Jonathan Pinnock Rama Ramachandran Bill Sheldon John Wiley & Sons
ISBN: 0-7645-5992-3
Chapter One
What Is Microsoft .NET? New technologies force change, nowhere more so than in computers and software. Occasionally, a new technology is so innovative that it forces us to challenge our most fundamental assumptions. In the computing industry, the latest such technology is the Internet. It has forced us to rethink how software should be created, deployed, and used.
However, that process takes time. Usually, when a powerful new technology comes along, it is first simply strapped onto existing platforms. So it has been for the Internet. Before the advent of Microsoft .NET, we used older platforms with new Internet capabilities "strapped on". The resulting systems worked, but they were expensive and difficult to produce, hard to use, and difficult to maintain.
Realizing this several years ago, Microsoft decided it was time to design a new platform from the ground up specifically for the post-Internet world. The result is called .NET. It represents a turning point in the world of Windows software for Microsoft platforms. Microsoft has staked their future on .NET, and publicly stated that henceforth almost all their research and development will be done on this platform. It is expected that, eventually, almost all Microsoft products will be ported to the .NET platform. (However, the name ".NET" will evolve, as we will see at the end of the chapter.)
What Is .NET?
Microsoft's .NET initiative is broad-based and very ambitious. It includes the .NET Framework, which encompasses the languages and execution platform, plus extensive class libraries providing rich built-in functionality. Besides the core .NET Framework, the .NET initiative includes protocols (such as the Simple Object Access Protocol, commonly known as SOAP) to provide a new level of software integration over the Internet, via a standard known as Web services.
Although Web services are important (and are discussed in detail in Chapter 22), the foundation of all .NET-based systems is the .NET Framework. This chapter will look at the .NET Framework from the viewpoint of a Visual Basic developer. Unless you are quite familiar with the Framework already, you should consider this introduction an essential first step in assimilating the information about Visual Basic .NET that will be presented in the rest of this book.
The first released product based on the .NET Framework was Visual Studio .NET 2002, which was publicly launched in February of 2002, and included version 1.0 of the .NET Framework. The current version is Visual Studio .NET 2003, which was introduced a year later, and included version 1.1 of the .NET Framework. This book assumes you are using VS.NET 2003, but almost all of the examples will work transparently with VS.NET 2002 because the differences in the two versions are minor.
A Broad and Deep Platform for the Future
Calling the .NET Framework a platform doesn't begin to describe how broad and deep it is. It encompasses a virtual machine that abstracts away much of the Windows API from development. It includes a class library with more functionality than any yet created. It makes available a development environment that spans multiple languages, and it exposes an architecture that makes multiple language integration simple and straightforward.
At first glance, some aspects of .NET appear similar to previous architectures, such as UCSD Pascal and Java. No doubt some of the ideas for .NET were inspired by these past efforts, but there are also many brand new architectural ideas in .NET. Overall, the result is a radically new approach to software development.
The vision of Microsoft .NET is globally distributed systems, using XML as the universal glue to allow functions running on different computers across an organization or across the world to come together in a single application. In this vision, systems from servers to wireless palmtops, with everything in between, will share the same general platform, with versions of .NET available for all of them, and with each of them able to integrate transparently with the others.
This does not leave out classic applications as we have always known them, though. Microsoft .NET also aims to make traditional business applications much easier to develop and deploy. Some of the technologies of the .NET Framework, such as Windows Forms, demonstrate that Microsoft has not forgotten the traditional business developer. In fact, such developers will find it possible to Internet-enable their applications more easily than with any previous platform.
What's Wrong with DNA and COM?
The pre-.NET technologies used for development on Microsoft platforms encompassed the COM (Component Object Model) standard for creation of components, and the DNA model for multitier software architectures. As these technologies were extended into larger, more enterprise-level settings, and as integration with the Internet began to be important, several major drawbacks became apparent. These included:
Difficulty in integrating Internet technologies:
Hard to produce Internet-based user interfaces
No standard way for systems and processes to communicate over the Internet Expensive, difficult, and undependable deployment
Poor cross-language integration
Weaknesses in the most popular Microsoft tool-Visual Basic:
Lack of full object orientation, which made it impossible to produce frameworks in Visual Basic
One threading model that did not work in some contexts
Poor integration with the Internet
Other weaknesses such as poor error handling capabilities
It is important to note that all pre-.NET platforms, such as Java, also have some of these drawbacks, as well as unique ones of their own. The drawbacks related to the Internet are particularly ubiquitous.
Let's take a brief look at these drawbacks to pre-.NET Microsoft technologies before taking up how .NET addresses them.
Difficulty in Integrating Internet Technologies
Starting in late 1995, Microsoft made a dramatic shift toward the Internet. They had to make some serious compromises to quickly produce Internet-based tools and technologies. The main result, Active Server Pages (ASP), was a tool that was not oriented around structured and object-oriented development. Having to design, debug, and maintain such unstructured ASP code is also a headache. While many viable systems were produced with ASP pages, these obvious flaws needed to be addressed.
Later in the evolution of the Internet, it became apparent that communicating with the user via HTTP and HTML was limiting. To get, for example, a stock quote from an Internet server, it was often necessary for a program to pretend to be a user, get an HTML page, and then take it apart to get the information needed. This was fussy development, and the result was quite brittle because of the possibility that the format of the page might change and, thus, need new parsing logic.
Developers needed a standard way for processes to communicate over the Internet, rather than the communication being directed only at users. DNA and COM lacked any such standard.
Deployment Issues
Microsoft's COM standard was developed for use on small systems with limited memory running Microsoft Windows. The design trade-offs for COM were oriented around sharing memory, and quick performance on hardware we would now consider slow.
This meant that Dynamic Link Libraries (DLLs) were shared between applications to save memory, and a binary interface standard was used to ensure good performance. To quickly find the components needed to run an application, DLLs had to register their class IDs to the local Windows Registry.
Besides the registration logistics needed to make DLLs work at all, COM components could be rendered inoperable by versioning issues. The resulting morass of problems related to versioning was colloquially known as "DLL Hell."
The need to register components locally also resulted in other limitations. It was not possible for a COM application to be placed on a CD-ROM or a network drive, and then run from that location without an installation procedure.
Poor Cross-Language Integration
COM/DNA typically required the use of three separate development models. Business components were most often written in Visual Basic, and Visual Basic could also be used for local Win32 user interfaces. Browser-based user interfaces required ASP. System components sometimes required the use of C++.
Each of these languages had difficulties integrating with the others. Getting VB strings properly transferred to and from C++ routines is a challenge. For example, ASP pages required a COM interface with only Variants for data, which negated the strong typing available in Visual Basic and C++. Getting all three languages to work together required several arcane skills.
Weaknesses in Visual Basic in COM/DNA Applications
Visual Basic 6 (VB6) (and earlier versions) was easily the most popular language for developing applications with the DNA model. As noted above, it can be used in two major roles-forms-based VB clients and COM components (on either the client or the server).
There are other options, of course, including C++, J++, and various third-party languages such as Delphi and Perl, but the number of VB developers outnumbers them all put together.
Despite its popularity, VB6 suffered from a number of limitations in the COM/DNA environment. Some of the most serious limitations include:
No capability for multithreading
Lack of implementation inheritance and other object-oriented features
Poor error handling ability
Poor integration with other languages such as C++ (as discussed above)
No effective user interface for Internet-based applications
Lack of multithreading implies, for example, that VB6 can't be used "out of the box" to write an NT-type service. There are also situations in which the apartment threading used by components created in Visual Basic limits performance.
VB6's limited object-oriented features, in particular the lack of inheritance, made it unsuitable for development of object-based frameworks, and denied design options to VB6 developers that were available to C++ or Java developers.
VB6's archaic error handling becomes especially annoying in a multitier environment. It is difficult in VB6 to track and pass errors through a stack of component interfaces.
Perhaps the biggest drawback to using VB6 became apparent when many developers moved to the Internet. While VB forms for a Win32 client were state-of-the-art, for applications with a browser interface, VB6 was relegated mostly to use in components because it did not have an effective way to do user interfaces for the Web.
Microsoft tried to address this problem in VB6 with Web classes and DHTML pages. Neither caught on because of their inherent limitations.
All of these limitations needed to be addressed, but Microsoft decided to look beyond just Visual Basic and solve these problems on a more global level. All of these limitations are solved in VB.NET through the use of technology in the .NET Framework.
An Overview of the .NET Framework
First and foremost, .NET is a framework that covers all the layers of software development above the operating system. It provides the richest level of integration among presentation technologies, component technologies, and data technologies ever seen on a Microsoft, or perhaps any, platform. Secondly, the entire architecture has been created to make it as easy to develop Internet applications, as it is to develop for the desktop.
The .NET Framework actually "wraps" the operating system, insulating software developed with .NET from most operating system specifics such as file handling and memory allocation. This prepares for a possible future in which the software developed for .NET is portable to a wide variety of hardware and operating system foundations.
VS.NET supports Windows 2003, Windows XP, and all versions of Windows 2000. Programs created for .NET can also run under Windows NT, Windows 98, and Windows Me, though VS.NET does not run on these systems.
The major components of the Microsoft .NET Framework are shown in Figure 1-1.
The framework starts all the way down at the memory management and component loading level, and goes all the way up to multiple ways of rendering user and program interfaces. In between, there are layers that provide just about any system-level capability that a developer would need.
At the base is the common language runtime, often abbreviated to CLR. This is the heart of the .NET Framework-it is the engine that drives key functionality. It includes, for example, a common system of datatypes. These common types, plus a standard interface convention, make cross-language inheritance possible. In addition to allocation and management of memory, the CLR also does reference tracking for objects, and handles garbage collection.
The middle layer includes the next generation of standard system services such as classes that manage data and XML. These services are brought under control of the framework, making them universally available and making their usage consistent across languages.
The top layer includes user and program interfaces. Windows Forms is a new and more advanced way to do standard Win32 screens (often referred to as "'smart clients"). Web Forms provides a new Web-based user interface. Perhaps the most revolutionary is Web services, which provides a mechanism for programs to communicate over the Internet, using SOAP. Web services provide an analog of COM and DCOM for object brokering and interfacing, but based on Internet technologies so that allowance is made even for integration to non-Microsoft platforms. Web Forms and Web services, which comprise the Internet interface portion of .NET, are implemented by a part of the .NET Framework referred to as ASP.NET.
All of these capabilities are available to any language that is based on the .NET platform, including, of course, VB.NET.
The Common Language Runtime
We are all familiar with runtimes-they go back further than DOS languages. However, the common language runtime (CLR) is as advanced over traditional runtimes as a machine gun is over a musket. Figure 1-2 shows a quick diagrammatic summary of the major pieces of the CLR.
That small part in the middle of Figure 1-2 called Execution support contains most of the capabilities normally associated with a language runtime (such as the VBRUNxxx.DLL runtime used with Visual Basic). The rest is new, at least for Microsoft platforms.
Continues...
Excerpted from Professional VB.NET 2003 by Bill Evjen Billy Hollis Rockford Lhotka Tim McCarthy Jonathan Pinnock Rama Ramachandran Bill Sheldon Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.