Building Distributed Applications with Visual Basic NET Dan Fox All Chapters Instant Download
Building Distributed Applications with Visual Basic NET Dan Fox All Chapters Instant Download
https://ebookfinal.com
https://ebookfinal.com/download/building-
distributed-applications-with-visual-basic-net-
dan-fox/
https://ebookfinal.com/download/developing-web-applications-with-
visual-basic-net-and-asp-net-1st-edition-john-alexander/
ebookfinal.com
https://ebookfinal.com/download/essential-asp-net-with-examples-in-
visual-basic-net-1st-edition-fritz-onion/
ebookfinal.com
https://ebookfinal.com/download/practical-database-programming-with-
visual-basic-net-1st-edition-ying-bai/
ebookfinal.com
https://ebookfinal.com/download/practical-database-programming-with-
visual-basic-net-2nd-edition-ying-bai/
ebookfinal.com
Mastering Visual Basic NET 1st Edition Petroutsos
https://ebookfinal.com/download/mastering-visual-basic-net-1st-
edition-petroutsos/
ebookfinal.com
Sams Teach Yourself ADO NET in 21 Days 1st Edition Dan Fox
https://ebookfinal.com/download/sams-teach-yourself-ado-net-
in-21-days-1st-edition-dan-fox/
ebookfinal.com
https://ebookfinal.com/download/visual-basic-net-bible-1st-edition-
bill-evjen/
ebookfinal.com
https://ebookfinal.com/download/visual-basic-and-visual-basic-net-for-
scientists-and-engineers-1st-edition-christopher-frenz-auth/
ebookfinal.com
https://ebookfinal.com/download/visual-basic-net-from-vb6-to-vb-
net-1st-edition-matt-tagliaferri/
ebookfinal.com
Building Distributed Applications with Visual Basic NET
Dan Fox Digital Instant Download
Author(s): Dan Fox
ISBN(s): 9780672321306, 0672321300
Edition: illustrated edition
File Details: PDF, 8.81 MB
Year: 2001
Language: english
Building Distributed Applications
with Visual Basic .NET
Dan Fox
Quilogy, Inc.
MEDIA DEVELOPER
Warning and Disclaimer Dan Scherf
Every effort has been made to make this book as complete and as accurate as
INTERIOR DESIGNER
possible, but no warranty or fitness is implied. The information provided is on
Anne Jones
an “as is” basis. The author(s) and the publisher shall have neither liability nor
responsibility to any person or entity with respect to any loss or damages aris- COVER DESIGNER
ing from the information contained in this book or from the use of programs Aren Howell
accompanying it.
Contents at a Glance
Foreword x
Introduction 1
Index 705
Foreword
The shift to .NET technologies is underway, bringing with it exciting opportunities that only
distributed computing makes possible. This I know to be true, having experienced the awesome
power of .NET technologies at work each day where our award-winning internal systems run
on the .NET platform.
As Chief Technology Officer at Quilogy, a provider of business solutions through digital con-
sulting, advanced hosting, and technical education, I have worked closely with Dan Fox over
the past several years learning, experimenting with, and applying new Microsoft technologies
to our own organization. For only by testing and building proven solutions for ourselves can
we be sure to provide our customers with the best, most effective solutions. Our work over the
past year to incorporate .NET strategies has been especially rewarding.
Dan’s demonstrated mastery of .NET technologies at Quilogy as well as his previous profes-
sional experiences building large-scale systems for a major oil company, extensive knowledge
of database and object-oriented systems, as well as numerous Microsoft certifications make
him uniquely qualified to write this book. Additionally, this year marks the 10th anniversary of
Visual Basic, which makes this book’s publication particularly meaningful. As we have found
for ourselves, the best way for professional VB developers to enter into the .NET sphere is
through Visual Basic .NET.
As the leading language used by corporate developers to build solutions, VB with its new .NET
qualities now can address even more of the needs and concerns of business developers, which
makes understanding it at this time so crucial. Part of the great news about .NET is that you
can move into it and still leverage your existing skills because of its multilanguage support. As
the book shows, there are some concepts and techniques you’ll need to learn, but they’ll build
on those you already have, so you can start to take advantage of all the new features and capa-
bilities that .NET has to offer.
Rather than restating Microsoft’s documentation, Dan explains the course of an application’s
development and offers wide-ranging insight as he delves into the whys, such as why VB .NET
is important, and the hows, such as how VB .NET fits into the general scheme. Additionally,
numerous code examples clearly illustrate key points and complement the book’s easy readabil-
ity. Dan is a sought-after instructor and speaker at such major events as TechEd and Developer
Days. He is also a regular contributor to several print and online magazines including Visual
Basic Programmers Journal, SQL Server Magazine, InformIT, and Advisor journals. His exem-
plary teaching methods, engaging speaking voice, and comprehensive knowledge shine through
in this book.
Currently as Technical Director, Dan is charged with helping me select technologies, set appli-
cation architecture, identify successful design patterns, and educate staff on emerging technolo-
gies. Since taking on this important position in the company, he has been instrumental in the
development of Quilogy’s breakthrough system for building portal solutions called Quilogy
Accelerator (QA). Using the code to Quilogy’s own intranet as a .NET accelerator, QA facili-
tates the process of creating portal and intranet solutions faster and less expensively than either
buying or building from scratch.
As we have found with QA and you will find as you apply .NET strategies to your own busi-
ness practices, .NET is changing the face of technological business solutions in extraordinarily
exciting new directions.
Alan Groh
CTO Quilogy
About the Author
Dan Fox is Technical Director for Quilogy in Overland Park, Kansas. Quilogy (www.quilogy.com)
is a leading Microsoft Gold Certified Partner and Solution Provider with more than 450 con-
sultants nationwide in 16 cities. Quilogy provides digital consulting and technical education
services to a wide range of clients and specializes in building solutions on the Microsoft plat-
form. As a Certified Technical Education Center, Quilogy teaches the range of Microsoft
Official Curriculum (MOC) courses and specializes in building solutions and teaching courses
using both .NET development and .NET Enterprise Servers.
Dan is a Microsoft Certified Solutions Developer, Systems Engineer, and Trainer who has been
a consultant, instructor, and managing consultant on a variety of projects. In his role as a
Technical Director, Dan provides technical guidance to Quilogy’s consultants and customers.
Before joining Quilogy in 1995, Dan worked for Chevron in Houston, Texas, and the National
Association of Insurance Commissioners in Kansas City, Missouri. Dan earned his B.S. in
Computer Science from Iowa State University in 1991.
Dan has been a frequent contributor to the Visual Basic Programmer’s Journal and has written
numerous articles for SQL Server magazine, Advisor journals, and InformIT.com. He authored
the book Pure Visual Basic from Sams and coauthored a book on the Visual Basic 6 Distributed
Exam (70-175) for Certification Insider Press. He has spoken at TechEd and several Developer
Days conferences and Microsoft events.
Dan lives in Shawnee, Kansas, with his lovely wife, Beth, and two young daughters, Laura and
Anna. Besides earning the nickname “Dan.NET” from his family, Dan spends his time reading,
enjoying movies, and as always, rooting for the Cubs.
Acknowledgments
First, I’d to thank the Senior Acquisitions Editor on this project at Sams, Sondra Scott. From
our initial contact, she has been an encouragement and a great person to work with. She made
sure that each step in the process went smoothly and provided excellent feedback early in the
process in the form of reviews. In addition, I’d like to thank Shannon Leuma, the Development
Editor, who was ever vigilant to keep me on schedule, make sure that the content was well
organized, and made many suggestions that served to make this a better book.
Of course, the two key elements of any technical book such as this, the actual written word and
the code, were greatly improved by the copyediting skills of Mike Henry and Geneil Breeze,
and the technical reviews of Phil Syme, Dan Suceava, and Eric Wilson. The five of them made
sure that the book was readable and contained accurate information, something that was diffi-
cult given the fact that the reviewers had to work with multiple beta versions of the product for
most of the development cycle.
As you can tell from the cover and forward, this book was a team effort by Quilogy, the com-
pany for which I work. President and CEO Randy Schilling and Chief Technology Officer
Alan Groh’s encouragement and investment in the project was instrumental to making it a suc-
cess. Because the book was developed so early in the product life cycle, their willingness to
give me the resources to develop a book of this scope, including both the time and travel to
Redmond, contributed greatly to the quality of the final result. Throughout the process, Quilogy
consultants and instructors reviewed the content and provided helpful advice and suggestions.
To all these talented people, I’m certainly indebted, particularly, Tim Vanover, Dave Wanta,
Jason Wisener, Sue Van Gels, Adrian Anttila, and Cathey Barrett.
In addition, the scope and purpose of the book was shaped and honed through excellent reviews
by Ari Bixhorn, VB Product Manager at Microsoft; Steve Hoag, Senior Technical Writer for
VB User Education at Microsoft; Kyle Lutes, Assistant Professor at the Computer Technology
Department of Purdue University; Richard Nelson, Senior Software Architect at Intuitive
Manufacturing Systems; Lars Powers, Vice President/Solution Development at Acclarant, Inc.;
Mike Snell, Chief Software Architect at Acclarant, Inc.; and Larry Wall, Team Leader Microsoft
Group at Synapse Technology. Thanks to all of you for your help.
And so, as is true of any book, this one was truly a team effort. That being said, any errors are
only mine, so feel free to e-mail me at dfox@quilogy.com with corrections and suggestions.
Finally and most importantly, I couldn’t have embarked on this project without the loving sup-
port of my wife, Beth, and daughters, Laura and Anna. Beth’s continuous encouragement and
patience during this project made it much easier to accomplish, and my girls as always pro-
vided the balance that keeps my technological pursuits in perspective.
Tell Us What You Think!
As the reader of this book, you are our most important critic and commentator. We value your
opinion and want to know what we’re doing right, what we could do better, what areas you’d
like to see us publish in, and any other words of wisdom you’re willing to pass our way.
As an associate publisher for Sams Publishing, I welcome your comments. You can e-mail
or write me directly to let me know what you did or didn’t like about this book—as well as
what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book,
and that due to the high volume of mail I receive, I might not be able to reply to every
message.
When you write, please be sure to include this book’s title and author as well as your name
and phone or fax number. I will carefully review your comments and share them with the
author and editors who worked on the book.
E-mail: feedback@samspublishing.com
uses SQL Server 2000 on the back end, so although ADO.NET supports accessing other
providers, the examples in this section and throughout the book will focus on SQL Server.
Chapter 8, “Building Components,” discusses how components are built in VB .NET. The
chapter also looks at legacy DLLs to ensure that your existing code can be used in .NET.
Finally, a discussion on how components in VB .NET applications can be shared with .NET
Remoting is presented, which, like its precursor DCOM, often comes in handy when the sub-
systems in a distributed application need to communicate across process and machine bound-
aries. Chapter 9, “Accessing Component Services,” logically follows by discussing how
business and data access logic in VB .NET components can be integrated with Windows 2000
Component Services. This allows your VB .NET components to take advantage of the object
pooling, just-in-time activation, transactional control, and other features VB developers rou-
tinely implement in distributed applications. In addition, this chapter shows how components
built in VB .NET can interoperate with classic COM components.
Part II is rounded out with Chapter 10, “Building Web Forms” and Chapter 11, “Building Web
Services,” which cover the aspects of the presentation services layer necessary to build a Web-
based application. In large part, Chapter 10 covers the architecture and features of ASP.NET
and how they differ from ASP and then discusses in detail the Web Forms programming model
using the UI of the Quilogy sample application for illustration. Chapter 11 introduces a second
type of interface that VB .NET can produce by discussing Web Services. Because Web
Services are a new concept to many developers, this chapter provides a foundation by explor-
ing the underlying technologies involved and how they are implemented in VB .NET.
can be thought of as a tool used to integrate the prebuilt components of the Services Framework
into a specific solution. Thinking of VB .NET this way should come as no surprise to existing
VB developers because the strength of previous versions of VB also was integrating prebuilt
and custom components.
The approach I recommend when reading the book is to read the entire section, tracking with
the code listings and snippets, and then perusing the online documentation or other sources for
any additional information before developing your own samples in your own problem domain
using the listings as a starting point. To help you in this endeavor, as mentioned earlier, the
code listings, along with the complete Quilogy sample application discussed in Chapters 7
through 11, can be found on the Sams Web site at www.samspublishing.com. To remind you of
this as you read, each chapter introduction includes the following note:
NOTE
All code listings and supplemental material for this chapter can be found on the
book’s Web site at www.samspublishing.com.
In addition, when using the listings, it should be noted that because in VB .NET the act of ref-
erencing external libraries usually entails placing an Imports statement at the beginning of
your code file, many of the code listings and examples contain shaded Imports statements at
the beginning. These are shaded because they wouldn’t appear in actual code in that location
but are required to produce the code found in the listing or example.
This book intentionally is heavy on code listings and short on figures. I believe that developers
can learn more quickly by viewing the code of others rather than through a tutorial or a simple
discussion. I tried to restrict the use of figures to those required to place a concept in context
or, for example, to give you an idea of where in the VS .NET UI to look for a particular fea-
ture. The screen shots should not be used as a tutorial, and as you work with VS .NET, the par-
ticulars of your solution will mean that the screens you see might differ.
I’ve also focused primarily on how you implement features using code rather than the graphi-
cal designers and wizards included in VS .NET. This too is intentional because I believe that to
develop a firm foundation you need to understand what’s happening at the code level and by
nature, graphical interactions and wizards don’t translate well to this medium.
COM components to house their data access and business logic and employing Microsoft
Transaction Server or Component Services. They are also versed in ADO and ASP develop-
ment and are just beginning to use XML. For these developers, the primary challenge when
moving to VB .NET is the object-oriented nature of the Services Framework and the additional
language syntax used to implement these features. As such, Chapters 3 and 4 will be especially
useful.
The secondary audience is the ASP developer who typically has less formal training and spe-
cializes in Web development. For these developers, the challenge is to move from building
two-tiered Web applications to a multitiered architecture, as described in Chapter 7. In addi-
tion, the richness of the VB .NET language, as opposed to VBScript or JScript, will require an
adjustment.
Finally, the many classes in the Services Framework that allow you to easily use system ser-
vices will open up a new world of possibilities. I’ve tried to highlight the portions of the
Services Framework (especially in Part III) that will be the most useful.
I wrote this book because I think that the underlying technology of the platform and the direc-
tion Microsoft has chosen with VB .NET make it ideally suited to developing distributed appli-
cations. However, the paradigm shift associated with the platform and the sheer size of the
product will make it difficult for some VB developers to get a handle on how to use VB .NET.
In the end, this book provides a bit of a roadmap and a survey of VB .NET and the Services
Framework and how it can be used to build distributed applications.
So what are you waiting for? Let’s get started by exploring the foundation of VB .NET: the
Microsoft .NET architecture.
Dan Fox
Shawnee, Kansas
August 2001
PART
.NET Concepts
I
IN THIS PART
1 The Microsoft .NET Architecture 9
1
Architecture
IN THIS CHAPTER
• A New Platform 11
As you are no doubt already aware, Visual Basic .NET (VB .NET) is far more than simply a
new release of Visual Basic. VB .NET is actually a piece in the larger puzzle of Microsoft’s
.NET architecture. This architecture encompasses not only a new release of Visual Studio
(Visual Studio .NET), which includes a suite of languages and a common platform on which
all the Visual Studio languages run referred to as the .NET Framework, but also new releases
of server products such as SQL Server 2000, BizTalk Server 2000, and Application Center
Server 2000, collectively referred to as .NET Enterprise Servers.
A Storm Coming?
In addition to the .NET development and server story, Microsoft has disclosed prelimi-
nary plans for building and hosting a set of Web-based services under the name .NET
My Services (formerly codenamed Hailstorm). Briefly, these services will be built using
technology in the .NET Framework and will allow users the ability to share and con-
sume personal information anywhere on any device. The core of the initiative is to
integrate disparate silos of information such as tasks, contacts, inbox, schedule, notifi-
cations, and favorites, among others, into a single secure Web-based information
store accessible via standard Internet protocols.
Currently, Passport, Microsoft’s authentication service, is the only publicly available
piece of this vision that is referred to both as Building Block Services and Foundation
Services. Passport integration in ASP.NET will be discussed in Chapter 10, “Building
Web Forms” while more information on .NET My Services can be found at
http://www.microsoft.com/myservices/default.asp.
Together, all these new tools are designed to help developers build modern, robust, distributed
applications. To help you understand how VB .NET fits into the architecture, this chapter will
discuss the platform and its implications for VB developers. Although this is a large chapter
with a lot of technical material, the differences in the fundamental architecture between previ-
ous versions of VB and VB .NET are significant. So significant, in fact, that you need to
immediately get a baseline for how these changes have been implemented and what they mean
to the larger picture of the .NET Framework and Visual Studio .NET.
NOTE
All code listings and supplemental material for this chapter can be found on the
book’s Web site at samspublishing.com.
The Microsoft .NET Architecture
11
CHAPTER 1
A New Platform 1
THE MICROSOFT
For corporate developers, application development has gone through several major shifts in the
ARCHITECTURE
last decade. As we started the 1990s, we were already immersed in the shift from developing
.NET
character-based monolithic mainframe applications to two-tier client/server applications on
PC-based hardware and operating systems utilizing ODBC-compliant relational databases and
graphical user interfaces (GUIs). At nearly the same time, we began to see the adoption of
object-oriented programming (OOP) concepts such as encapsulation, inheritance, polymor-
phism, and reusable components into development tools such as PowerBuilder and Visual
Basic. With a subsequent move to distributed computing relying on n-tier architectures and
component-based programming, by early 1997, many of these tools and technologies were rel-
atively mature, widely distributed, and entrenched in the corporate developer community.
From the perspective of a corporate developer utilizing Microsoft products, this produced an
architecture in which a Visual Studio client application written in VB or Microsoft Foundation
Classes (MFC) communicated with COM components running in Microsoft Transaction Server
(MTS) using the DCOM protocol. The components themselves accessed a relational database
such as SQL Server or Oracle using an ODBC driver or, later, an OLEDB provider. By utiliz-
ing the object context, MTS gave developers the ability to handle transactions across these het-
erogeneous databases using XA (a subset of services from the X/Open Distributed Transaction
Processing (DTP)) and centralized object destruction and creation.
Of course, the largest change had reached critical mass by 1997 with the widespread adoption
of the Internet, HTML, and now XML. Although Microsoft released a new development tool,
Visual InterDev (VID), and a programming model for Web development, Active Server Pages
(ASP), both of these were largely additions to the existing architecture that provided integra-
tion with existing components and relational databases, but did not alter the way development
was done in the core Visual Studio languages Visual Basic and Visual C++. In addition, the
programming model and visual design tools provided in VID and ASP were not nearly as
robust as those in the more mature products. Attempts to integrate Web programming into VB,
such as the inclusion of ActiveX documents, DHTML applications, and Web classes, only
illustrated the point that at their core, the flagship development tools were ill-suited for life in a
Web world. One of the main reasons for this is that the tools relied on technology—such as the
Win32 API, COM, and DCOM—that was developed in the early 1990s when desktop comput-
ing was central and when persistently connected clients in an insulated LAN environment were
the norm.
Developing applications for which the Internet is the platform requires a different mindset—a
mindset that moves from thinking of writing software for only internal consumption to one in
which all users of the Internet are your potential customers. And this requires different technol-
ogy that is up to the task of incorporating support for the loosely coupled nature of clients and
.NET Concepts
12
PART I
servers, a new security model, and the integration of industry standard HTTP and XML as
ubiquitous protocols. I don’t know about you, but if all this could be packaged within a modern
object-oriented framework that provides maximum reusability and developer productivity, it
sounds like a platform I’d like to use.
And so, at its core, the .NET Framework and Visual Studio .NET (which I’ll refer to together
as simply .NET) are tools designed to take advantage of the Internet as the major platform for
application development. At the highest level, the goals for the initial release were to produce a
development environment:
• Where the Internet and Internet standards are second nature
• Where distributed Web applications are easy to build
• That combines the power of object-oriented programming and relieves the burdens of
complicated versioning and deployment
In the remainder of this section and chapter, I’ll talk specifically about what .NET is and dis-
cover how Visual Basic .NET fits in.
important than being able to run the same binary on various platforms. In addition, the amount 1
of integration possible in .NET far exceeds that provided by COM and extends all the way to
THE MICROSOFT
ARCHITECTURE
cross-language inheritance.
.NET
In any case, Microsoft’s vision for platform independence relies on industry standards such as
Simple Object Access Protocol (SOAP), an XML-based protocol, to make cross-platform calls
and interact with services exposed over the Web (also known as XML Web Services).
Companies throughout the industry from IBM to Sun are supporting the SOAP standard now
in the hands of the W3C (http://www.w3.org/TR/SOAP/), and so its inclusion in .NET moves
us forward to the time when applications built on differing platforms will be able to communi-
cate seamlessly.
NOTE
For a look at a variety of Web Services built on various platforms, see
www.xmethods.net.
On the other side of the fence, .NET is a new platform for developing distributed Web applica-
tions. .NET mainstreams the concept of Web Services as programmable application compo-
nents accessible via standard Web protocols. The .NET Framework includes hundreds of
prebuilt classes that encapsulate these Web standards and protocols to provide a great founda-
tion for building both interactive Web applications and Web Services, as I’ll discuss in
Chapters 10, “Building Web Forms,” and 11, “Building Web Services.”
.NET also provides a new model for building and sharing components. As you’re probably
aware, the reliance of classic COM components on registry entries, Globally Unique
Identifiers (GUIDs), v-tables, and IUnknown makes distributing and invoking those compo-
nents across the network using DCOM sometimes tricky. In .NET, all those concepts go away
and are replaced by a simpler mechanism that allows remoting of components across the net-
work, easy deployment, and side-by-side versioning of components on the same machine. You
will explore many of these concepts in Chapters 5, “Packaging, Deployment, and Security,”
and 8, “Building Components.”
Finally, .NET is a Rapid Application Development (RAD) tool for distributed applications.
The inclusion of the Server Explorer window in the VS. NET IDE (covered in Chapter 2, “The
Development Environment”), the .NET Framework classes for manipulating data through
ADO.NET (covered in Chapter 7, “Accessing Data with ADO.NET”), and integrating with
both low-level system services such as threading (covered in Chapter 12, “Accessing System
Services”) and high-level services such as messaging and Active Directory (covered in Chapter
14, “Integrating with the Enterprise”) make it a high-productivity environment.
.NET Concepts
14
PART I
NOTE
The phrase in theory in the previous paragraph refers to the fact that compilers, as
well as the .NET Framework, play a role in performance. Even if the VB .NET language
contains syntactical equivalents for all VC# constructs, the VB .NET compiler would
still have to produce intermediate language code (as discussed later) identical to that
produced by the VC# compiler in order for two applications to perform identically.
This is unlikely, and so in certain circumstances a language built on the .NET
Framework might outperform another language when executing similar operations.
However, these small differences will also tend to even out in the scope of an entire
application.
In the initial release of VS .NET, VC++ will be the only language through which you
can create code that does not use the CLR at all. VC# will allow you to write code
blocks that do not use the CLR and so in both cases, when using these features, all
bets on performance are off.
Entire books have been written on how to extend VB to implement specific features (and break
through the “glass ceiling”) of the Win32 API, such as threading, callbacks, and writing NT
services. (I know because I’ve written one of them.) However, with VB .NET, all these features
are transparent and accessible through a set of class libraries that ship with VS .NET, called the
.NET Framework classes or the Services Framework. Using the Services Framework in your
applications allows VB .NET to support the RAD model that VB developers have come to
expect.
The Microsoft .NET Architecture
15
CHAPTER 1
NOTE 1
THE MICROSOFT
ARCHITECTURE
Throughout this book I’ll use the term Services Framework to refer to the entire col-
.NET
lection of over a thousand classes that ship with Visual Studio .NET, both those that
implement support for the various programming models such as Web Forms and Web
Services, and the lower-level classes that implement network communication, IO,
threading, and so on. Some authors will refer to the entire collection as simply the
.NET Framework, .NET Frameworks, or Base Class Libraries (BCL). Although I seldom
use the term, I reserve BCL for the lower-level classes upon which the higher-level
programming models are built.
The second point to consider is that VB .NET not only encompasses the functionality of previ-
ous versions of VB to create form-based applications and components, it also can be used to
create Web applications using a robust event-driven programming model. In other words, the
functionality of the forms package and ASP have been abstracted into application program-
ming models and exposed to all the .NET programming languages through reusable framework
classes.
NOTE
As a result of the inclusion of the Web-based programming into the Services
Framework, developers who in the past used Visual InterDev as their primary tool will
likely be migrating to VB .NET. For developers, moving from a language such as
VBScript, which did not support types other than Variant and lacked support for
more sophisticated features like classes and events, to the robust .NET languages
might at first seem daunting. For those developers I say, bear with me. Much of the
information in this chapter is crucial for getting the big picture. That being said,
those developers will find more of the information for which they are looking, and
can move through the book using a faster track, by concentrating on Chapters 2, 3, 4,
7, 10, and 11.
In addition, many of the intrinsic functions and statements have been abstracted into the
Services Framework and the CLR, the result being that VB .NET actually contains fewer
keywords than previous versions. A picture of how these parts fit together can be seen in
Figure 1.1.
.NET Concepts
16
PART I
NOTE
VB .NET is a Common Language Specification (CLS)–compliant language and so it can
take advantage of the CLR. There is a more complete discussion of the CLS later in
this chapter.
Services Framework
Microsoft .NET Framework <
Common Language Runtime
SOAP
HTTP
Internet Standards <
TCP/IP
FIGURE 1.1
The .NET architecture. Much of the functionality of previous versions of VB has been abstracted into the application
programming models and Services Framework.
Taken together, you can infer that VB .NET is different from previous versions of VB because
it is now only one of many languages that take advantage of the services provided by the .NET
Framework. This is great for VB developers because they can now access all the features .NET
provides without paying the price of increased complexity, kludgy workarounds, and degraded
performance.
In the remainder of this chapter, I’ll drill down on the foundation of Figure 1.1 and discuss the
key concepts behind the CLR and the Services Framework.
NOTE 1
THE MICROSOFT
ARCHITECTURE
See Jeffery Richter’s series of articles on the MSDN Web site (msdn.microsoft.com) for
.NET
more details on the CLR.
As was true with VB 6.0 and COM, developers creating distributed applications could get
by with developing their applications without any appreciation for the internals of COM.
However, extending that knowledge just a little bit allows you to create applications that take
full advantage of what the CLR provides.
NOTE
COM does support the notion of interface inheritance so that one object can imple-
ment another’s interfaces (which defines the required method and property signa-
tures including the method names, arguments, and return values, if any). This allows
you to write polymorphic code and could also be done in VB 6.0 (see Chapter 15 of
my book, Pure Visual Basic, Sams Publishing, August 1999, for a more in-depth discus-
sion). However, this technique does not allow the actual code inside the object to be
reused. Implementation inheritance means that one object can be derived from
another and that when the derived object is executed, the code from the parent will
also run if desired. This leads to greater code reuse, although there are pitfalls as
well. We’ll look more closely at these features as they’ve been added to VB .NET in
Chapter 4, “Object-Oriented Features.”
The CLR provides the common substrate within which all the software runs so that objects can
directly interact, and so that all the plumbing code is eliminated from both the components
themselves and the operating system. For example, in the COM world, components were
responsible for the in-memory layout of their objects into v-table structures so that the appro-
priate methods could be located at runtime. Now, however, this responsibility has been relieved
from the components and is handled by the CLR.
Because all VB .NET code is run by the CLR, it can provide services like those listed here:
• Different compilation models—As I’ll discuss shortly, the abstraction of the CLR from
the development languages allows the runtime to determine when an application is com-
piled.
• Automatic lifetime management—Because all objects—and everything is ultimately an
object in .NET—are managed by the CLR, it can monitor when those objects are created
and used, and when they are no longer needed. As a result, it will use a garbage collec-
tion (GC) algorithm to free resources as necessary. This means that you can no longer
have stray pointers and that circular references will be resolved. In fact, you are no
longer responsible for freeing resources (setting an object to Nothing, for example) at all.
This is great news, but it changes the way you will design your code, for example,
because Terminate events are no longer supported. I’ll cover this topic in more detail
both in this chapter and in Chapter 3, “VB .NET Language Features.”
• Code correctness and type-safety—VB developers have always taken for granted that
in many cases they could assign a variable of one type to another and VB would auto-
matically convert it for them. By default, however, the CLR strictly enforces type safety
so that developers can’t make arbitrary references to memory locations and make unsafe
The Microsoft .NET Architecture
19
CHAPTER 1
casts—things that VB developers typically don’t care about, but that happen frequently 1
in VC++ and are exploited by hackers. What it means to VB .NET developers is that
THE MICROSOFT
ARCHITECTURE
there is a new default behavior and more levels of type safety that can be used. I’ll cover
this in detail in Chapter 3.
.NET
• Simplified deployment—Because the CLR eliminates the plumbing required for com-
ponents to communicate, it also reduces the installation and deployment burden for
developers. By eliminating registration (for the most part, as you’ll see in Chapter 5.)
and allowing features such as side-by-side execution both on the same machine and even
within the same process, some .NET applications can be deployed simply by copying
directories (referred to as XCOPY deployment).
• Evidence-based security—This new platform also requires a new security model. In the
past, security models typically relied on the credentials of the user running the code.
However, in distributed applications where code can be downloaded from the Internet
and executed, the code itself needs to be trusted. The .NET security model is not simply
a rehashing of the Microsoft Authenticode technology used for signing and encrypting
ActiveX controls; it is a new model based on evidence provided by both the code as well
as the user (through operating system accounts or roles) and is policy-based. In addition,
the security model can be accessed both declaratively and imperatively inside your code.
I will discuss this in more detail in Chapter 5.
• Common exception handling—As mentioned previously, the varying programming
models used by corporate developers all handle errors in different ways. COM uses
HRESULTs, the Win32 API uses function return values with a second call to retrieve the
error, ASP uses inline error handling, and VB uses error trapping within a module. The
CLR includes structured exception handling, which allows isolation of the error code and
works well across language boundaries. I’ll discuss how VB .NET implements this fea-
ture in Chapter 6, “Error Handling and Debugging.”
These features of the CLR allow languages to work together and leverage common tools such
as the debugger and profiler so that cross-language and even cross-machine debugging (cov-
ered in Chapter 6) are simplified. This results in a greater freedom to use the language of your
choice without sacrifice. This is, once again, good news for VB .NET developers.
And finally, as implied earlier and discussed in the following sections, the all-encompassing
nature of the CLR gives it the nature of a Hardware Abstraction Layer (HAL) and makes it
possible to write code that might not require recompilation as you move it to a new platform.
Initially, Microsoft is planning to port the CLR to its family of operating systems including
Windows 98, Windows Me, Windows NT 4.0, Windows 2000, Windows XP, 64-bit Windows,
and even Windows CE in a package called the .NET Compact Framework. In the future, other
non-Microsoft operating systems might also be included.
.NET Concepts
20
PART I
NOTE
As mentioned previously, only VC++ can produce unmanaged code. The default mode
for VC++ is to create unmanaged code, and so the product is referred to as “Visual
C++ with managed extensions.” However, VC# will also allow you to write unman-
aged code within a method by using the unsafe modifier. As a result, a VC# devel-
oper can use pointers and override the GC algorithm in certain cases to keep it from
freeing resources using a technique called pinning. As implied by its name, the
unsafe modifier can allow developers to override the features of the CLR noted in
the “Automatic lifetime management” bullet point earlier and therefore create stray
pointers and unresolved circular references. Note, however, that this unmanaged
code will run only if the code is trusted by the CLR security model.
VB .NET produces only managed code and so must use the interoperability features of .NET
(referred to simply as “interop”) to access any form of unmanaged code. We’ll take a look at
how this is accomplished in Chapter 9, “Accessing Component Services.”
One of the ramifications of this for VB .NET developers is that upgrading VB 6.0 projects to
VB .NET (covered in Chapter 3) means that the interop services will be relied upon heavily,
which adds a layer of complexity and slows performance. For these and other reasons, VB
.NET developers will need to be very careful when deciding what and when to upgrade.
The Microsoft .NET Architecture
21
CHAPTER 1
Death of COM?
1
THE MICROSOFT
ARCHITECTURE
With all these changes, what does this mean for COM? Well, the good news is that
because VB hid many of the complexities of COM from developers, changing the
.NET
infrastructure should not inconvenience most developers. In addition, doing away
with the headaches of GUIDs and the registry, the single-version-per-machine scheme
that it implied, as well as dealing with compatibility settings, are all a good thing. Is
COM dead? Yes, in terms of its infrastructure.
However, many corporate VB developers have a good understanding of COM and
take advantage of interface-based programming in their designs. These developers
can still use the same techniques in their designs, while they can also augment them
with implementation inheritance. Is COM dead? No, in terms of the concept of shar-
ing and reusing code.
In any case, many of us will have to coexist in both worlds for some time to come. For
example, one of the most common scenarios will be that newly developed managed
code (perhaps a new ASP.NET UI or Web Service) will need to call previously deployed
COM+ components written in VB 6.0. For this to work, VB .NET developers will need
to be aware of both the old and new worlds and how they interoperate (as I’ll discuss
in Chapter 9). In fact, it might be argued that some new VB .NET developers will need
a short course on classic COM to implement scenarios like the one mentioned.
NOTE
Strictly speaking, the CLS binds vendors to rules only for types that are made public
and accessible outside a particular assembly. Assemblies will be covered in more detail
at the end of this chapter.
.NET Concepts
22
PART I
In fact, the CLS dictates a subset of what the CLR provides for languages to be compatible.
Individual vendors can then implement more of the functionality if they desire. The CLS
defines three levels for compatibility:
• consumers—Languages that use the CLR but do not extend it
• extenders—Languages that use the CLR and extend it by adding additional data types
• frameworks—Languages that implement libraries used by a wide range of programming
languages and tools
As of this time, many vendors have indicated their willingness to create compilers for lan-
guages such as Pascal, Smalltalk, LISP, FORTRAN, Perl, and over 20 others. In fact, Microsoft
has even produced a version of Java (J# .NET) that targets the CLR as a part of its JUMP (Java
User Migration Path) program.
To assist in this effort, Microsoft and Hewlett Packard jointly submitted the CLS, CLR
(referred to as the Common Language Infrastructure), and the C# language specification to the
international industry standards body ECMA. See msdn.microsoft.com/net/ecma and
www.ecma.ch for more details.
NOTE
Obviously, this book is geared towards existing VB and ASP developers, and as such, I
am definitely of the opinion that these developers will be much more productive
much sooner using VB .NET than VC# due to the syntax similarities. In addition, VB
.NET preserves much of what was good about BASIC to begin with, namely a more
readable and hence understandable syntax. VC# was designed with C++ and Java
developers in mind and so will be the natural path to .NET for those developers. That
being said, VC# is in many respects more like VB .NET than C++, and so many VB
developers will have no trouble reading and understanding the syntax.
CLR Internals
To help you get a feel for how the CLR works, I’ll use an inside-out approach by first dis-
cussing what happens on a binary level and then moving up to a single application level, cross-
application level, and finally to the cross-machine and deployment level. I’ll begin the
discussion by focusing on how code is compiled and executed for the CLR.
MSIL
As with any executable today, the code you write in VB .NET eventually must execute as
native CPU instructions for the processor on which the code will be run. However, although
unmanaged compilers create these native CPU instructions directly, and interpreters such as
The Microsoft .NET Architecture
23
CHAPTER 1
ASP create instructions on the fly that map to CPU instructions, the managed compilers written 1
for the CLR, which include VB .NET, create a higher level, machine-independent set of
THE MICROSOFT
ARCHITECTURE
instructions referred to as Microsoft Intermediate Language (MSIL). The MSIL instructions
are then stored in a portable executable (PE) file with a .DLL or .EXE extension based on the
.NET
Microsoft Portable Executable format, which itself extends the Common Object File Format
(COFF) commonly used for executable content. These files are referred to as modules in .NET
(not to be confused with VB modules as discussed in Chapter 2). MSIL is eventually loaded by
the CLR and compiled to native instructions and executed.
To view the MSIL created by the VB .NET compiler, you can use the IL Disassembler utility
(ILDasm.exe) that ships with .NET. This graphical utility lets you view each method in your
program, along with its associated MSIL, by double-clicking on the method. Figure 1.2 shows
ILDasm opened up on a method called AddOrder in a class called Orders.
FIGURE 1.2
The IL Disassembler. This graphical utility lets you view the MSIL created for your VB .NET code. Note that the
instructions begin with IL_0000 in the foreground window.
This basic architecture and its implications should be familiar to VB developers. First, it means
that VB. NET binaries are not native code but a form of intermediate code as was true for most
of VB’s history. The big difference is that MSIL is a much lower level set of instructions than
the interpreted code produced in previous versions of VB. Although you might be thinking that
Random documents with unrelated
content Scribd suggests to you:
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com