Back to description
This chapter introduces the core elements that make up Visual Basic 2008. Every software development language has unique... more
This chapter introduces the core elements that make up Visual Basic 2008. Every software development language has unique elements of syntax and behavior. Visual Basic 2008 has evolved significantly since Visual Basic was introduced in 1991. Although Visual Basic has its origins in traditional procedural-based programming languages, it began the transition to objects back in 1995 with Visual Basic 4.0.
With the release of Visual Basic .NET (that is, Version 7) Visual Basic became a fully object-oriented programming environment. Now with the release of Visual Basic 2008 (that is, Version 9) there are still more new features, but at the core are the same basic types and commands that have been with Visual Basic since its early stages. Object paradigms extend the core elements of the language. Therefore, while a very brief introduction to the existence of classes and objects within the language is presented in this chapter, the key concepts of object-oriented development are presented in detail in Chapters 2 and 3.
This chapter focuses on the core elements of the language, including questions about those language elements a new developer not familiar with Visual Basic might ask, such as where semicolons should be placed. The key topics of this chapter include the following:
Initial syntax and keywords to understand the basic language elements
Value versus reference types
Primitive types
Commands: If Then Else, Select Case
If Then Else
Select Case
Value types (structures)
Reference types (classes)
Commands: For Each, For Next, Do While
For Each
For Next
Do While
Boxing
Parameter passing ByVal and ByRef
ByVal
ByRef
Variable scope
Data type conversions, compiler options, and XML literals
The main goal of this chapter is to familiarize you with Visual Basic. The chapter begins by looking at some of the keywords and language syntax you need. Experienced developers will probably gloss over this information, as this is just a basic introduction to working with Visual Basic. After this, the chapter discusses primitive types and then introduces you to the key branching commands for Visual Basic. After you are able to handle simple conditions, the chapter introduces value and reference types. The code then looks at working with collections and introduces the primary looping control structure syntax for Visual Basic.
After this there is a brief discussion of boxing and value type conversions, conversions which often implicitly occur when values are passed as parameters. Following these topics is a discussion of variable scope, which defines the code that can see variables based on where they are defined in relationship to that block of code. Finally, the chapter introduces basic data type conversions, which includes looking at the compiler options for Visual Studio 2008. Visual Studio 2008 includes a new compiler option and a new data type, XML literals, which are also introduced in the context of conversions.
... less
Visual Basic supports the four major defining concepts required for a language to be fully object-oriented:... more
Visual Basic supports the four major defining concepts required for a language to be fully object-oriented:
AbstractionAbstraction is merely the ability of a language to create “black box” code, to take a concept and create an abstract representation of that concept within a program. A Customer object, for instance, is an abstract representation of a real-world customer. A DataTable object is an abstract representation of a set of data.
Customer
DataTable
EncapsulationThis is the concept of a separation between interface and implementation. The idea is that you can create an interface (Public methods, properties, fields, and events in a class), and, as long as that interface remains consistent, the application can interact with your objects. This remains true even when you entirely rewrite the code within a given methodthus, the interface is independent of the implementation. Encapsulation enables you to hide the internal implementation details of a class. For example, the algorithm you use to compute pi might be proprietary. You can expose a simple API to the end user, but hide all the logic used by the algorithm by encapsulating it within your class.
Public
PolymorphismPolymorphism is reflected in the ability to write one routine that can operate on objects from more than one classtreating different objects from different classes in exactly the same way. For instance, if both the Customer and the Vendor objects have a Name property and you can write a routine that calls the Name property regardless of whether you are using a Customer or Vendor object, then you have polymorphism.
Vendor
Name
Visual Basic supports polymorphism in two waysthrough late binding (much like Smalltalk, a classic example of a true object-oriented language) and through the implementation of multiple interfaces. This flexibility is very powerful and is preserved within Visual Basic.
InheritanceInheritance is the idea that a class can gain the interface and behaviors of a preexisting class. This is done by inheriting these behaviors from the existing class through a process known as subclassing.
The next chapter discusses these four concepts in detail; this chapter focuses on the syntax that enables you to utilize these concepts.
Visual Basic is also a component-based language. Component-based design is often viewed as a successor to object-oriented design, so component-based languages have some other capabilities. These are closely related to the traditional concepts of object orientation:
Multiple interfacesEach class in Visual Basic defines a primary interface (also called the default or native interface) through its Public methods, properties, and events. Classes can also implement other, secondary interfaces in addition to this primary interface. An object based on this class has multiple interfaces, and a client application can choose with which interface it will interact with the object.
Assembly (component) level scopingNot only can you define your classes and methods as Public (available to anyone), Protected (available through inheritance), and Private (available only locally), you can also define them as Friendmeaning they are available only within the current assembly or component. This is not a traditional object-oriented concept, but is very powerful when used with component-based applications.
Protected
Private
Friend
This chapter explains how to create and use classes and objects in Visual Basic. We won’t get too deeply into code, but it is important that you spend a little time familiarizing yourself with basic object-oriented terms and concepts.
Visual Basic is a fully object-oriented language. Chapter 2 covered the basics of creating classes and objects, including... more
Visual Basic is a fully object-oriented language. Chapter 2 covered the basics of creating classes and objects, including the creation of methods, properties, events, operators, and instance variables. You have seen the basic building blocks for abstraction, encapsulation, and polymorphismconcepts discussed in more detail at the end of this chapter. The final major techniques you need to understand are inheritance and the use of multiple interfaces.
Inheritance is the idea that you can create a class that reuses methods, properties, events, and variables from another class. You can create a class with some basic functionality, and then use that class as a base from which to create other, more detailed, classes. All these derived classes will have the same common functionality as that base class, along with new, enhanced, or even completely changed functionality.
This chapter covers the syntax that supports inheritance within Visual Basic. This includes creating the base classes from which other classes can be derived, as well as creating those derived classes.
Visual Basic also supports a related concept: multiple interfaces. As shown in Chapter 2, all objects have a native or default interface, which is defined by the public methods, properties, and events declared in the class. In the .NET environment, an object can have other interfaces in addition to this native interfacein other words, .NET objects can have multiple interfaces.
These secondary interfaces define alternative ways in which your object can be accessed by providing clearly defined sets of methods, properties, and events. Like the native interface, these secondary interfaces define how the client code can interact with your object, essentially providing a “contract” that enables the client to know exactly what methods, properties, and events the object will provide. When you write code to interact with an object, you can choose which of the interfaces you want to use; basically, you are choosing how you want to view or interact with that object.
This chapter uses relatively basic code examples so that you can focus on the technical and syntactic issues surrounding inheritance and multiple interfaces. The last part of this chapter revisits these concepts using a more sophisticated set of code as you continue to explore object-oriented programming and how to apply inheritance and multiple interfaces in a practical manner.
Of course, just knowing the syntax and learning the tools is not enough to be successful. Successfully applying Visual Basic’s object-oriented capabilities requires an understanding of object-oriented programming. This chapter also applies Visual Basic’s object-oriented syntax, showing how it enables you to build object-oriented applications. It also describes the four major object-oriented concepts: abstraction, encapsulation, polymorphism, and inheritance. By the end of this chapter, you will understand how to apply these concepts in your design and development efforts to create effective object-oriented applications.
You’ve learned how to create simple applications and looked at how to create classes. Now it’s time not only to start tying... more
You’ve learned how to create simple applications and looked at how to create classes. Now it’s time not only to start tying these elements together, but also to learn how to dispose of some of the classes that you have created. The architects of .NET realized that all procedural languages require certain base functionality. For example, many languages ship with their own runtime that provides features such as memory management, but what if, instead of each language shipping with its own runtime implementation, all languages used a common runtime? This would provide languages with a standard environment and access to all of the same features. This is exactly what the common language runtime (CLR) provides.
The CLR manages the execution of code on the .NET platform. .NET provided Visual Basic developers with better support for many advanced features, including operator overloading, implementation inheritance, threading, and the ability to marshal objects. Building such features into a language is not trivial. The CLR enabled Microsoft to concentrate on building this plumbing one time and then reuse it across different programming languages. Because the CLR supports these features and because Visual Basic is built on top of the CLR, Visual Basic can use these features. As a result, going forward, Visual Basic is the equal of every other .NET language, with the CLR eliminating many of the shortcomings of the previous versions of Visual Basic.
Visual Basic developers can view the CLR as a better Visual Basic runtime. However, this runtime, unlike the old standalone Visual Basic runtime, is common across all of .NET regardless of the underlying operating system. Thus, the functionality exposed by the CLR is available to all .NET languages; more important, all of the features available to other .NET languages via the CLR are available to Visual Basic developers. Additionally, as long as you develop using managed codecode that runs in the CLRyou’ll find that it doesn’t matter whether your application is installed on a Windows XP client or a Vista client; your application will run. The CLR provides an abstraction layer separate from the details of the operating system.
This chapter gets down into the belly of the application runtime environment, not to examine how .NET enables this abstraction from the operating system, but instead to look at some specific features related to how you build applications that run against the CLR. This includes an introduction to several basic elements of working with applications that run in the CLR, including the following:
Elements of a .NET application
Versioning and deployment
Integration across .NET languages
Microsoft Intermediate Language (MSIL)
Memory management and the garbage collector (GC)
Developers usually build their applications in the English language. Then, as the audience for the application expands, they... more
Developers usually build their applications in the English language. Then, as the audience for the application expands, they realize the need to globalize the application. Of course, the ideal is to build the application to handle an international audience right from the start, but in many cases this may not be possible because of the extra work it requires.
With the.NET Framework 3.5, a considerable effort has been made to address the internationalization of .NET applications. Changes to the API, the addition of capabilities to the server controls, and even Visual Studio itself equip you to do the extra work required to bring your application to an international audience. This chapter looks at some of the important items to consider when building your applications for the world.
One of the things developers often need to do is create new types for their programs. Early attempts at type creation led... more
One of the things developers often need to do is create new types for their programs. Early attempts at type creation led to user-defined types, or the use of the VB Structure statement. Another approach is to use classes and objects to create new types. Ever since the release of the .NET Framework 2.0, another approach is to use generics.
Structure
Generics refers to the technology built into the .NET Framework 3.5 (and the .NET Framework versions 2.0 and 3.0) that enables you to define a code template and then declare variables using that template. The template defines the operations that the new type can perform; and when you declare a variable based on the template, you are creating a new type. The benefit of generics over structures or objects is that a generic template makes it easier for your new types to be strongly typed. Generics also make it easier to reuse the template code in different scenarios.
The primary motivation for adding generics to .NET was to enable the creation of strongly typed collection types. Because generic collection types are strongly typed, they are significantly faster than the previous inheritance-based collection model. Anywhere you presently use collection classes in your code, you should consider revising that code to use generic collection types instead.
Visual Basic 2008 allows not only the use of preexisting generics, but also the creation of your own generic templates. Because the technology to support generics was created primarily to build collection classes, it naturally follows that you might create a generic collection anytime you would otherwise build a normal collection class. More specifically, anytime you find yourself using the Object data type, you should instead consider using generics.
Object
This chapter begins with a brief discussion of the use of generics, followed by a walk-through of the syntax for defining your own generic templates.
Even if you did not realize it, you have been using namespaces since the beginning of this book. For example,... more
Even if you did not realize it, you have been using namespaces since the beginning of this book. For example, System, System.Diagnostics, and System.Windows.Forms are all namespaces contained within the .NET Framework. Namespaces are an easy concept to understand, but this chapter puts the ideas behind them on a firm footingand clears up any misconceptions you might have about how they are used and organized.
System
System.Diagnostics
System.Windows.Forms
If you are familiar with COM, you will find that the concept of namespaces is the logical extension of programmatic identifier (ProgID) values. For example, the functionality of Visual Basic 6’s FileSystemObject is now mostly encompassed in .NET’s System.IO namespace, though this is not a one-to-one mapping. However, namespaces reflect more than a change in name; they represent the logical extension of the COM naming structure, expanding its ease of use and extensibility.
ProgID
FileSystemObject
System.IO
In addition to the traditional System and Microsoft namespaces (for example, used in things such as Microsoft’s Web Services Enhancements), the .NET Framework 3.5 includes a way to access some tough-to-find namespaces using the My namespace. The My namespace is a powerful way of “speed-dialing” specific functionalities in the base.
Microsoft
My
This chapter about namespaces covers the following:
What namespaces are
Which namespaces are used in Visual Studio 2008 projects by default
How to reference namespaces and use the Imports statement
Imports
How the compiler searches for class references
How to alias namespaces and create your own namespaces
How to use the My namespace
All professional-grade programs need to handle unexpected conditions. In programming languages before Microsoft .NET, this... more
All professional-grade programs need to handle unexpected conditions. In programming languages before Microsoft .NET, this was often called error handling. Unexpected conditions generated error codes, which were trapped by programming logic that took appropriate action.
The common language runtime in .NET does not generate error codes. When an unexpected condition occurs, the CLR creates a special object called an exception. This object contains properties and methods that describe the unexpected condition in detail and provide various items of useful information about what went wrong.
Because the .NET Framework deals with exceptions instead of errors, the term error handling is seldom used in the .NET world. Instead, the term exception handling is preferred. This term refers to the techniques used in .NET to detect exceptions and take appropriate action.
This chapter covers how exception handling works in Visual Basic 2008. It discusses the common language runtime (CLR) exception handler in detail and the programming methods that are most efficient in catching errors. Specifically, it covers the following:
A very brief overview of error handling in Visual Basic 6 (VB6), for those just moving to .NET
The general principles behind exception handling
The Try...Catch...Finally structure, the Exit Try statement, and nested Try structures
Try
Catch
Finally
Exit
The exception object’s methods and properties
Capabilities in Visual Studio for working with exceptions
Error and trace logging and how you can use these methods to obtain feedback about how your program is working
ADO.NET 1.x was the successor to ActiveX Data Objects 2.6 (ADO). The main goal of ADO.NET 1.x was to enable developers to... more
ADO.NET 1.x was the successor to ActiveX Data Objects 2.6 (ADO). The main goal of ADO.NET 1.x was to enable developers to easily create distributed, data-sharing applications in the .NET Framework. The main goals of ADO.NET today are to improve the performance of existing features in ADO.NET 1.x, to provide easier use and to add new features without breaking backward compatibility.
Note
Throughout this chapter, when ADO.NET is mentioned without a version number after it (that is, 1.x, 2.0, or 3.5), the statement applies to all versions of ADO.NET.
ADO.NET 1.x was built upon industry standards such as XML, and it provided a data access interface to communicate with data sources such as SQL Server and Oracle. ADO.NET 3.5 builds upon these concepts, while increasing performance. Applications can use ADO.NET to connect to these data sources and retrieve, manipulate, and update data. ADO.NET 3.5 does not break any compatibility with ADO.NET 2.0 or 1.x; it only adds to the stack of functionality.
In solutions that require disconnected or remote access to data, ADO.NET 3.5 uses XML to exchange data between programs or with Web pages. Any component that can read XML can make use of ADO.NET components. A receiving component does not even have to be an ADO.NET component if a transmitting ADO.NET component packages and delivers a data set in an XML format. Transmitting information in XML-formatted data sets enables programmers to easily separate the data-processing and user interface components of a data-sharing application onto separate servers. This can greatly improve both the performance and maintainability of systems that support many users.
For distributed applications, ADO.NET 1.x proved that the use of XML data sets provided performance advantages relative to the COM marshaling used to transmit disconnected data sets in ADO. Because transmission of data sets occurred through XML streams in a simple text-based standard accepted throughout the industry, receiving components did not require any of the architectural restrictions required by COM. XML data sets used in ADO.NET 1.x also avoided the processing cost of converting values in the Fields collection of a Recordset to data types recognized by COM. Virtually any two components from different systems can share XML data sets provided that they both use the same XML schema for formatting the data set. This continues to be true in ADO.NET 3.5, but the story gets better. The XML integration in ADO.NET today is even stronger now, and extensive work was done to improve the performance of the DataSet object, particularly in the areas of serialization and memory usage.
Recordset
DataSet
ADO.NET also supports the scalability required by Web-based data-sharing applications. Web applications must often serve hundreds, or even thousands, of users. By default, ADO.NET does not retain lengthy database locks or active connections that monopolize limited resources. This enables the number of users to grow with only a small increase in the demands made on the resources of a system.
In this chapter, you will see that ADO.NET is a very extensive and flexible API for accessing many types of data, and because ADO.NET 3.5 is an incremental change to the previous versions of ADO.NET, all previous ADO.NET knowledge already learned can be leveraged. In fact, to get the most out of this chapter you should be fairly familiar with earlier versions of ADO.NET and the entire .NET Framework.
This chapter demonstrates how to use the ADO.NET object model in order to build flexible, fast, scalable data access objects and applications. Specifically, it covers the following:
The ADO.NET architecture
Some of the specific features offered in ADO.NET, including batch updates, DataSet performance improvements, and asynchronous processing
Working with the Common Provider Model
Building a data access component
This chapter describes how you can generate and manipulate Extensible Markup Language (XML) using Visual Basic 2008. Of course... more
This chapter describes how you can generate and manipulate Extensible Markup Language (XML) using Visual Basic 2008. Of course, using XML in Visual Basic is a vast area to cover (more than possibly could be covered in a chapter). The .NET Framework exposes five XML-specific namespaces that contain over a hundred different classes. In addition, dozens of other classes support and implement XML-related technologies, such as ADO.NET, SQL Server, and BizTalk. Consequently, this chapter focuses on the general concepts and the most important classes.
Visual Basic relies on the classes exposed in the following XML-related namespaces to transform, manipulate, and stream XML documents:
System.Xml provides core support for a variety of XML standards, including DTD, namespace, DOM, XDR, XPath, XSLT, and SOAP.
System.Xml
System.Xml.Serialization provides the objects used to transform objects to and from XML documents or streams using serialization.
System.Xml.Serialization
System.Xml.Schema provides a set of objects that enable schemas to be loaded, created, and streamed. This support is achieved using a suite of objects that support in-memory manipulation of the entities that compose an XML schema.
System.Xml.Schema
System.Xml.XPath provides a parser and evaluation engine for the XML Path language (XPath).
System.Xml.XPath
System.Xml.Xsl provides the objects necessary when working with Extensible Stylesheet Language (XSL) and XSL Transformations (XSLT).
System.Xml.Xsl
The XML-related technologies utilized by Visual Basic include other technologies that generate XML documents and enable XML documents to be managed as a data source:
ADOThe legacy COM objects provided by ADO can generate XML documents in stream or file form. ADO can also retrieve a previously persisted XML document and manipulate it. (Although ADO is not used in this chapter, ADO and other legacy COM APIs can be accessed seamlessly from Visual Basic.)
ADO.NETThis uses XML as its underlying data representation: The in-memory data representation of the ADO.NET DataSet object is XML; the results of data queries are represented as XML documents; XML can be imported into a DataSet and exported from a DataSet. (ADO.NET is covered in Chapter 9.)
SQL Server 2000XML-specific features were added to SQL Server 2000 (FOR XML queries to retrieve XML documents and OPENXML to represent an XML document as a rowset). Visual Basic can use ADO.NET to access SQL Server’s XML-specific features (the documents generated and consumed by SQL Server can then be manipulated programmatically). Recently, Microsoft also released SQLXML, which provides a SQL Server 2000 database with some excellent XML capabilities, such as querying a database using XQuery, getting back XML result sets from a database, working with data just as if it were XML, taking huge XML files and having SQLXML convert them to relational data, and much more. SQLXML enables you to perform these functions and more via a set of managed .NET classes. You can download SQLXML free from the Microsoft SQLXML website at http://msdn2.microsoft.com/aa286527.aspx.
FOR XML
OPENXML
http://msdn2.microsoft.com/aa286527.aspx
SQL Server 2005SQL Server has now been modified with XML in mind. SQL Server 2005 can natively understand XML because it is now built into the underlying foundation of the database. SQL Server 2005 includes an XML data type that also supports an XSD schema validation. The capability to query and understand XML documents is a valuable addition to this database server. SQL Server 2005 also comes in a lightweight (and free) version called SQL Server Express Edition.
SQL Server 2008The latest edition of SQL Server, version 2008, works off of the SQL Server 2005 release and brings to the table an improved XSD schema validation process as well as enhanced support for XQuery.
This chapter makes sense of this range of technologies by introducing some basic XML concepts and demonstrating how Visual Basic, in conjunction with the .NET Framework, can make use of XML. Specifically, in this chapter you will do all of the following:
Learn the rationale behind XML.
Look at the namespaces within the .NET Framework class library that deal with XML and XML-related technologies.
Take a close look at some of the classes contained within these namespaces.
Gain an overview of some of the other Microsoft technologies that utilize XML, particularly SQL Server and ADO.NET.
At the end of this chapter, you will be able to generate, manipulate, and transform XML using Visual Basic.
This book also covers LINQ to XML and the new XML objects found in the System.Xml.Linq namespace. These items are covered in Chapter 11.
System.Xml.Linq
Probably the biggest and most exciting addition to the .NET Framework 3.5 is the addition of the .NET Language Integrated... more
Probably the biggest and most exciting addition to the .NET Framework 3.5 is the addition of the .NET Language Integrated Query Framework (LINQ) into Visual Basic 2008. Basically, what LINQ provides is a lightweight façade over programmatic data integration. This is a big deal, because data is king.
Pretty much every application deals with data in some manner, whether that data comes from memory (in-memory data), databases, XML files, text files, or somewhere else. Many developers find it very difficult to move from the strongly typed, object-oriented world of Visual Basic to the data tier, where objects are second-class citizens. The transition from the one world to the next was a kludge at best and full of error-prone actions.
In VB, programming with objects means a wonderful strongly typed ability to work with code. You can navigate very easily through the namespaces, work with a debugger in the Visual Studio IDE, and more. However, when you have to access data, you will notice that things are dramatically different.
You end up in a world that is not strongly typed, and debugging is a pain or even nonexistent. You end up spending most of the time sending strings to the database as commands. As a developer, you also have to be aware of the underlying data and how it is structured or how all the data points relate.
Microsoft has provided LINQ as a lightweight façade that provides a strongly typed interface to the underlying data stores. LINQ provides the means for developers to stay within the coding environment they’re used to and access the underlying data as objects that work with the IDE, IntelliSense, and even debugging.
With LINQ, the queries that you create now become first-class citizens within the .NET Framework alongside everything else you are used to. When you begin to work with queries for the data store you’re working with, you will quickly realize that they now work and behave as if they were types in the system. This means that you can now use any .NET-complaint language and query the underlying data store as you never have before.
Looking at the figure, you can see that different types of LINQ capabilities are available depending on the underlying data you’re going to be working with in your application:
LINQ to Objects
LINQ to DataSets
LINQ to SQL
LINQ to Entities
LINQ to XML
As a developer, you are given class libraries that provide objects that, using LINQ, can be queried like any other data store. In fact, objects are nothing more than data that is stored in memory. Indeed, your objects themselves might be querying data. This is where LINQ to Objects comes into play.
LINQ to SQL, LINQ to Entities, and LINQ to DataSets provide the means to query relational data. Using LINQ, you can query directly against your database and even against the stored procedures that your database exposes. The last thing item in the diagram is the capability to query against your XML using LINQ to XML. What makes LINQ so exciting is that it matters very little what you are querying against, as your queries will be quite similar.
This chapter takes a close look at LINQ to SQL and LINQ to XML. You will get a taste of how to perform LINQ to Object queries via this focus as well.
This chapter covers the basics of security and cryptography. It begins with a brief discussion of the .NET Framework’s security... more
This chapter covers the basics of security and cryptography. It begins with a brief discussion of the .NET Framework’s security architecture, because this affects all the solutions you may choose to implement.
The .NET Framework provides you with additional tools and functionality with regard to security. You now have the System.Security.Permissions namespace, which enables you to control code access permissions along with role-based and identity permissions. Through your code, you can control access to objects programmatically, as well as receive information on the current permissions of objects. This security framework will assist you in determining whether you have permissions to run your code, instead of getting halfway through execution and having to deal with permission-based exceptions. This chapter covers the following:
System.Security.Permissions
Concepts and definitions
Permissions
Roles
Principals
Code access permissions
Role-based permissions
Identity permissions
Managing permissions and policies
Cryptography
Cryptography is the cornerstone of the .NET Web Services security model, so the second half of this chapter discusses the basis of cryptography and how to implement it. Specifically, it covers the following:
Hash algorithms
SHA
MD5
Secret key encryption
Public key cryptography standard
Digital signatures
Certification
Secure Sockets Layer communications
Let’s begin by looking at some security concepts and definitions.
Tip
As always, the code for this chapter is available for download from www.wrox.com, which you may want in order to follow along.
www.wrox.com
It’s possible to work with Visual Basic without Visual Studio. In practice, however, the two are almost inseparable; without... more
It’s possible to work with Visual Basic without Visual Studio. In practice, however, the two are almost inseparable; without a version of Visual Studio, you’re forced to work from the command line to create project files by hand, to make calls to the associated compilers, and to manually address the tools necessary to build your application. Thus, while it is possible, Visual Studio 2008 is the preferred environment for developing Visual Basic applications.
With the release of Visual Studio 2005, Microsoft expanded on the different versions of Visual Studio available for use. Unlike the early versions, they’ve expanded what we’ll call the high-end and low-end packages associated with Visual Studio. At the low-cost end, currently free, is Visual Basic Express Edition. This tool enables you to build desktop applications with Visual Basic only. Its companion for Web development is Visual Web Developer Express, which enables you to build ASP.NET applications. At the high end, Microsoft offers Visual Studio Team System, available only with a high-cost MSDN subscription, which includes many tools that extend Visual Studio beyond the core Integrated Development Environment (IDE) to help improve design, testing, and collaboration between developers.
Of course, the focus of this chapter is how Visual Studio enables you to use Visual Basic to build applications geared toward “better, faster, cheaper” business goals. To this end, we’ll be examining features of Visual Studio starting with those in the core Visual Basic 2008 Express Edition and building up to the full Visual Studio Team Suite. Topics in this chapter include the following:
Versions of Visual Studio
Project templates
Project propertiesapplication, compilation, debug, and so on
Setting properties
IntelliSense, code expansion, and code snippets
Targeting a runtime environment
Debugging
Recording and using macros
The Class Designer
Visual Studio tools for Office
Team SystemTeam Suite Client Tools
Team Foundation ServerTeam Explorer
This chapter provides an overview of many of the capabilities of Visual Studio 2008, with a brief introduction to the features available by using one of the more feature-rich versions of Visual Studio. The goal is to demonstrate how Visual Studio makes you, as a developer, more productive and successful.
While most of the relationship between a developer and an SQL Server relates to querying or saving data, Visual Studio 2008... more
While most of the relationship between a developer and an SQL Server relates to querying or saving data, Visual Studio 2008 provides a couple of ways to work with databases: SQL Server Compact Edition and SQL CLR.
While Visual Basic has always included tools for working with the various editions and versions of SQL Server, Visual Studio 2008 includes a new member of the SQL Server family: SQL Server Compact Edition (SQLCE). SQLCE is a lightweight version of the database that requires minimal installation and configuration to use. It runs on both Windows and devices running Windows CE. SQLCE is particularly suited for creating local caches of a larger remote database, which may be used to improve performance when querying rarely changing tables or for the creation of partially connected solutions when working with data. In combination with various synchronization scenarios, SQLCE can provide developers with a powerful tool for enabling their applications to work both connected to the main database and offline (still storing records until the next connection).
SQL Server 2005 added integration with the .NET Framework. This provided two main benefits. First, you can use Visual Basic to create elements in the database, such as user-defined types, stored procedures, and functions. These objects may work alone or in concert with Transact-SQL objects. Second, you can expose Web services from your databases, enabling .NET and other client applications to execute code on the database.
Transact-SQL (T-SQL), while well-featured, lacks a number of features that are common in general-purpose languages such as Visual Basic. VB includes better support for looping and conditional statements than T-SQL. In addition to these language features, the .NET Framework is available for use with Visual Basic, meaning you have access to tools for network access, string handling, mathematical processing, internationalization, and more. Therefore, if your stored procedures need access to features such as these, it may be beneficial to look at using VB as the language, not T-SQL.
This chapter describes how you can use Visual Basic to create applications that save data to SQLCE databases, and how to create database objects in SQL Server 2005. It covers some of the synchronization methods you can take advantage of to create partially connected applications. This chapter also covers the capability of hosting CLR objects and Web services within SQL Server and how you can create these objects using Visual Basic.
Windows Forms is a part of the .NET Framework that is used to create user interfaces for local applications, often called... more
Windows Forms is a part of the .NET Framework that is used to create user interfaces for local applications, often called Win32 clients. Windows Forms does not change in moving from Visual Basic 2005 to Visual Basic 2008. Accordingly, the version number used for Windows Forms in Visual Studio 2008 is still 2.0.
The pace of change in Windows Forms is slowing because of the advent of Windows Presentation Foundation (WPF). Visual Studio 2008 is the first version of Visual Studio with a capable visual designer for WPF. Going forward, you can expect continued innovation in WPF, but not much in Windows Forms. However, that does not imply that you should abandon Windows Forms or be reluctant to write programs in it. Windows Forms still has many advantages over WPF.
Those advantages include a more complete set of controls and a mature, easy-to-use designer. The result is faster development in Windows Forms compared to WPF. WPF has advantages of its own, of course. These are discussed in Chapter 17, which provides an introduction to WPF.
This chapter summarizes the changes in Windows Forms 2.0 compared to the earlier 1.0 and 1.1 versions that were present in Visual Studio 2002 and 2003. This enables those with some experience in previous versions of Windows Forms to quickly identify key changes. Then the chapter looks at the behavior of forms and controls, with emphasis on those elements that are most important for routine application development.
Chapter 16 includes more advanced treatment of certain aspects of Windows Forms. After gaining a basic understanding of the key capabilities in this chapter, you’ll be ready to go on to the more advanced concepts in that chapter.
The previous chapter discussed the basics of Windows Forms 2.0. These capabilities are sufficient for straightforward user... more
The previous chapter discussed the basics of Windows Forms 2.0. These capabilities are sufficient for straightforward user interfaces for systems written in VB 2008, along with the built-in capabilities of forms and controls available in Windows Forms 2.0.
However, as applications become larger and more complex, it becomes more important to use the advanced capabilities of the .NET environment to better structure the application. Poorly structured large systems tend to have redundant code. Repeated code patterns end up being used (in slightly different variations) in many, many places in an application, which has numerous bad side effectslonger development time, less reliability, more difficult debugging and testing, and tougher maintenance.
Examples of needs that often result in repeated code include ensuring that fields are entered by the user, that the fields are formatted correctly, and that null fields in the database are handled correctly. Proper object-oriented design can encapsulate such functionality, making it unnecessary to use repeated code. Using the full object-oriented capabilities of the .NET environment, plus additional capabilities specific to Windows Forms programming, you can componentize your logic, allowing the same code to be used in numerous places in your application.
null
This chapter discusses techniques for componentizing code in Windows Forms applications. It is assumed that you have already read Chapters 2 and 3 on inheritance and other object-oriented techniques available in .NET before working with this chapter.
Windows Presentation Foundation (WPF)previously known as Avalonis the next-generation presentation library and development... more
Windows Presentation Foundation (WPF)previously known as Avalonis the next-generation presentation library and development paradigm for user interfaces. It was introduced with Windows Vista as a key architectural component in the .NET 3.0 Framework. This chapter introduces you to the WPF programming model and discusses key elements you’ll need to know in order to work with WPF. Rest assured you will be creating applications that leverage the features of WPF in the future. Visual Studio introduces a fully enabled development environment for creating and customizing WPF-based applications.
The libraries that make up WPF were released in conjunction with the release of Windows Vistanot the commercial and much-publicized public launch of Vista in January 2007, but the initial release of Vista to enterprise partners in November 2006. The libraries shipped with Vista and coincidentally with Microsoft Office 2007, but what you may or may not have noticed at the time was the lack of development tools.
However, with Visual Studio 2008, not only are there tools for the .NET 3.5 libraries, but also tools for all of the .NET 3.0 libraries. Additionally, Microsoft released the Expression suite of tools, in particular Blend, which you’ll also need if you are going to create custom WPF applications.
This chapter covers several key areas, including the following:
The WPF strategy
Why you should use WPF
Creating a WPF application
XAML
Implementing a custom WPF application
Customizing the user interface
Using Blend for custom graphics and behavior
This chapter introduces a basic WPF application and then focuses on the underlying XAML that’s used to declare WPF and other applications. Then it picks up with a custom WPF Windows framework application that you can leverage. The goal is to introduce you to WPF in a manner that should be familiar to Windows Forms developers and then expand on what additional items WPF brings to the equation. This chapter will not make you an expert WPF developerWPF is too large a topic to fully cover in a single chapterbut it does provide a good starting place.
Windows Presentation Foundation (WPF) was introduced in the preceding chapter as Microsoft’s next-generation solution to... more
Windows Presentation Foundation (WPF) was introduced in the preceding chapter as Microsoft’s next-generation solution to graphical user-interface development. In terms of user interfaces, the transition to this new model will be similar in significance and paradigm shift to the shift from COM-based Visual Basic to Visual Basic .NET. In other words, the paradigms and syntax familiar to developers of Windows applications are changing, and most of the changes are not backwardly compatible. Currently, there are no plans for an automated migration from any existing user-interface paradigm, forms, or Web, to the new WPF format.
You will need to transition existing application source code to a new technology paradigm. Perhaps not this year or next, but at some point the WPF paradigm will be used to update the look and feel of existing applications. How will this transition compare to the last major .NET-related transitionthe one from COM? The original version of Visual Studio .NET included a tool to aid in migrating code from the COM-based world to .NET. No migration tool will be provided to transition existing user interfaces to WPF, which should be considered a good thing, considering the history of the current migration tools.
Instead, Microsoft learned the lesson that migration is both difficult and time consuming and is best done at the developer’s pace. This is seen in the new Power Pack tools for Visual Basic, which Microsoft first released in 2006. These tools, which are now on version 2.0, are covered in Appendix B and are similar in concept to the interop methodology that Microsoft has chosen to follow with WPF. Microsoft is providing libraries that enable user-interface developers to integrate these two interface models. In the long run, this integration will probably go the way of COM-Interop, which is to say it will be available but carry such a stigma that people will only use it when absolutely necessary.
This chapter takes you through several key areas of Windows Forms integration, including the following:
The Integration Librarycode-named Crossbow
Using WPF controls in Windows Forms
Using Windows Forms controls in WPF
Interop limitations
The focus of this chapter is how to use these libraries to best enable you to both leverage WPF with your existing code and leverage your existing code and related Forms-based code with your new WPF applications. Just as with COM-Interop, the point of this tool is to help you, the developer, transition your application from Windows Forms to WPF over time, while working with time and budget constraints that all developers face and potentially waiting on the availability of a control that isn’t available in WPF.
The introduction of ASP.NET 1.0/1.1 changed the Web programming model, and ASP.NET 3.5 is just as revolutionary in the way... more
The introduction of ASP.NET 1.0/1.1 changed the Web programming model, and ASP.NET 3.5 is just as revolutionary in the way it increases the productivity of .NET developers. The primary goal of ASP.NET is to enable you to build powerful, secure, and dynamic applications using the least possible amount of code. This chapter covers some of the exciting features provided by ASP.NET 3.5 and most of what the ASP.NET technology offers.
ASP.NET is an exciting technology. It enables the creation and delivery of remotely generated applications... more
ASP.NET is an exciting technology. It enables the creation and delivery of remotely generated applications (Web applications) accessible via a simple browsera container that many are rather familiar with. The purpose of Web-based applications (in our case, ASP.NET applications) is to deliver only a single instance of the application to the end user over HTTP. This means that the end users viewing your application will always have the latest and greatest version at their disposal. Because of this, many companies today are looking at ASP.NET to not only deliver the company’s website, but also to deliver some of their latest applications for their employees, partners, and customers.
The last chapter looked at some of the basics of ASP.NET 3.5. This chapter continues that exploration, showing you some additional and exciting technologies that you will find in ASP.NET 3.5, including master pages, configuration, data access, and more.
This chapter touches upon many topics, as ASP.NET has become a rather large offering with many possibilities and capabilities. Sit back, pull up that keyboard, and enjoy!
One of the newer technologies out there is Silverlight 1.0, which was released in September of 2007. At the time of this... more
One of the newer technologies out there is Silverlight 1.0, which was released in September of 2007. At the time of this writing, Silverlight 1.0 is the only production release of the product. However, Silverlight 2.0 will be released in the first half of 2008.
Silverlight is a lightweight browser plug-in from Microsoft that, much like Adobe’s Flash, will allow for greater fluidity in your applications, thereby providing a rich user experience like no other in ASP.NET. The base of Silverlight is XAMLa new markup language for creating applications by Microsoft, such as WPF (Windows Presentation Foundation) applications.
You can build Silverlight applications using Microsoft’s new Expression Blend IDE, as well as the new Visual Studio 2008. This chapter looks at the basics of Silverlight and how to build a Silverlight application.
This chapter introduces the Visual Studio Tools for Office (VSTO) project templates. VSTO has been around as an add-in to... more
This chapter introduces the Visual Studio Tools for Office (VSTO) project templates. VSTO has been around as an add-in to Visual Studio for several releases. Visual Studio 2008 includes it as part of the standard installation of all versions of Visual Studio Professional and above. The VSTO package isn’t so much a set of new menus as it is templates and DLLs that enable you to integrate custom business logic into Microsoft Office products.
VSTO has been somewhat neglected in the .NET development world. The main Office client applications that most people think about to target, Word and Excel, have supported customization through Visual Basic for Applications (VBA) since long before .NET, so for most developers the power of VSTO hasn’t really been leveraged. With the release of Office 2007 and the new project types available in Visual Studio 2008, you can expect Outlook to start to take center stage in terms of Office-based application customization.
More important, Visual Studio 2008 not only introduces VSTO as a mainline set of tools with Visual Studio Professional Edition and above, but also provides one of the largest deltas in terms of new features from previous versions of anything in Visual Studio 2008. These new features are intended to provide much more end-to-end use of VSTO to enable the creation of business applications.
This chapter introduces you to the role of the VSTO family of tools and demonstrates three different implementation examples. The topics in this chapter include the following:
VSTO releases
Office business application architecture
VBA-VSTO interop
Creating a document template (Word)
Creating an Office add-in (Excel)
Outlook form regions
These tools are available as part of Visual Studio 2008 Professional and are focused on enabling you to move from a goal of “this project will create a custom grid with the following capabilities” to a goal of “this project will enable users to leverage Excel 2007 and surface our business application data in the robust Excel table management system, where users can customize and save the data back into our custom line-of-business data store.” Developers and customers often talk about how nice it would be to embed Excel in their application. Now, as you’ll see in this chapter, the real solution is the reverseyour application can be embedded in Excel.
By now, you’ve probably developed some programs in .NET, so you’ve seen the modules produced by the .NET compilers, which... more
By now, you’ve probably developed some programs in .NET, so you’ve seen the modules produced by the .NET compilers, which have file extensions of .dll or .exe. Most .NET modules are DLLs, including class libraries and those that serve as code-behind for ASP.NET. Windows applications, console applications, and Windows Services are examples of .NET modules that are executables and thus have an extension of .exe.
dll
exe
These .NET-compiled modules, both DLLs and EXEs, are referred to as assemblies. Assemblies are the unit of deployment in .NET, containing both compiled code and metadata that is needed by the .NET common language runtime (CLR) to run the code. Metadata includes information such as the code’s identity and version, dependencies on other assemblies, and a list of types and resources exposed by the assembly.
Basic development in .NET doesn’t require you to know any more than that. However, as your applications become more complex, and as you begin considering such issues as deployment and maintenance of your code, you need to understand more about assemblies. This chapter addresses that need, including the following:
What assemblies are and how they are used
The general structure of an assembly
How assemblies can be versioned
The global application cache (GAC), including how and when to use it
How assemblies are located and loaded by the CLR
After you are familiar with these essentials, Chapter 24 uses this information to discuss deployment in depth.
Applications developed with the .NET Framework have a host of deployment options that were not available for older, COM-based... more
Applications developed with the .NET Framework have a host of deployment options that were not available for older, COM-based software. These options completely change the economics of deployment. The changes are so important that they can even alter the preferred architecture for a system written in .NET.
Deployment encompasses many activities required to place an application into a production environment, including setting up databases, placing software in appropriate directories on servers, and configuring options for a particular installation. Deployment also includes handling changes and upgrades to the application.
This chapter covers the major deployment options for .NET applications. The previous chapter on assemblies should be considered a prerequisite for this chapter, as assemblies are the basic unit of deployment.
First, you’ll look at some of the problems that can occur when you deploy applications, along with a number of terms that are used when talking about application deployment. Then you’ll learn how .NET addresses many of these deployment issues. The remainder of the chapter covers the following:
Creating deployment projects in Visual Studio 2008 that enable initial installation of applications
Deployment of the .NET Framework itself on systems where it does not already reside
Updating applications on servers, including components and ASP.NET applications
Installing and updating Windows Forms applications on client machines with ClickOnce
Deployment in .NET is a huge topic that can’t be covered completely within one chapter. This chapter should provide you with a basic understanding of the options available, and a desire to learn more about them.
However much we try, we just cannot ignore the vast body of technology surrounding Microsoft’s Component Object Model... more
However much we try, we just cannot ignore the vast body of technology surrounding Microsoft’s Component Object Model (COM). Over the years, this model has been the cornerstone of so much Microsoft-related development that we have to take a long, hard look at how we are going to integrate all that technology into the world of .NET.
This chapter begins by taking a brief backward glance at COM, and then compares it with the way that components interact in .NET. It also takes a look at the tools Microsoft provides to help link the two together. Having looked at the theory, you then try it out by building a few example applications. First you take a legacy basic COM object and run it from a Visual Basic 2008 program. Then you repeat the trick with a full-blown ActiveX control. Finally, you run some Visual Basic code in the guise of a COM object.
More information on how to make COM and VB6 code interoperate with the .NET platform can be found in Professional Visual Basic Interoperability: COM and VB6 to .NET (Wiley, 2002).
As you do all that, keep in mind one thing: COM is, to a large extent, where .NET came from. In addition, with all the time and resources that have been invested in this technology, it is important to consider the best ways to both maintain these investments and integrate them into new investments you make.
One of the results of the move from 16-bit to 32-bit computing was the ability to write code that made use of threads, but... more
One of the results of the move from 16-bit to 32-bit computing was the ability to write code that made use of threads, but although Visual C++ developers have been able to use threads for some time, Visual Basic developers have not had a truly reliable way to do so, until now. Previous techniques involved accessing the threading functionality available to Visual C++ developers. Although this worked, actually developing multithreaded code without adequate debugger support in the Visual Basic environment was nothing short of a nightmare.
For most developers, the primary motivation for multithreading is the ability to perform long-running tasks in the background while still providing the user with an interactive interface. Another common scenario is when building server-side code that can perform multiple long-running tasks at the same time. In that case, each task can be run on a separate thread, enabling all the tasks to run in parallel.
This chapter introduces you to the various objects in the .NET Framework that enable any .NET language to be used to develop multithreaded applications.
While Windows Communication Foundation and Windows Presentation Foundation enjoy much of the attention, the .NET Framework... more
While Windows Communication Foundation and Windows Presentation Foundation enjoy much of the attention, the .NET Framework 3.0 also comes with another “Foundation”: Windows Workflow Foundation (usually abbreviated WF). WF can be a powerful tool in developing applications, as it provides a standard means of adding workflow to an application. Workflow refers to the steps involved in an application. Most business applications contain one or more workflows, such as the approval steps in an expense-tracking application or the steps involved in paying for a cart full of items at an online store. Normally, a workflow is created in code and is inextricably bound to the application. WF enables developers to graphically build the workflow, keeping it logically separated from the code itself. It also enables the workflow to change as the needs of the business change. These workflows may be as complex as needed and may integrate human processes or Web services.
This chapter looks at how you can take advantage of WF in your applications: how you can add and edit workflows, how you can integrate workflows into an existing business process, and how the graphical tools used to build workflows with Visual Studio can help you communicate with business users and avoid errors caused by mistakes in the workflow.
This chapter begins with a short history of multi-tier architecture and network operating systems, a discussion of the early... more
This chapter begins with a short history of multi-tier architecture and network operating systems, a discussion of the early days of the “network as the computer,” and a discussion of where system architecture is heading today. The reason for this diversion is to understand the rationale behind Web services.
The chapter next looks at a sample Web service and walks through the process of making it accessible to the Internet as well as accessing it from a client applicationboth with the Visual Studio IDE and using command-line tools. From there, the chapter moves on to a key feature of Web services: the Service Repository, Discovery, and Universal Description, Discovery, and Integration (UDDI) features that enable remote programmers to correctly access Web services.
Finally, the chapter delves into more in-depth topics during discussion of the four namespaces found in the .NET Framework class library that deal with Web services and how to utilize them with Visual Basic 2008. Moving on, the chapter covers topics such as security, transactions, and the downsides of any distributed architecture (including any downsides associated with the Web services model), followed by a short discussion of where you go from here and how to get there.
Remoting is the .NET technology that enables code in one application domain... more
Remoting is the .NET technology that enables code in one application domain (AppDomain) to call into the methods and properties of objects running in another application domain. A major use of remoting is in the classic n-tier desktop approach, where presentation code on the desktop needs to access objects running on a server somewhere on the network. Another primary use for remoting is when code in ASP.NET Web Forms or Web Services needs to call objects running on an application server somewhere else on the network. In short, remoting is the technology to use when your n-tier code needs to talk to the business or data tier that is running on an application server.
AppDomain
Remoting is conceptually somewhat similar to Web services. Both remoting and Web services are TCP/IP-based technologies that enable communication between different machines over an IP network. This means that they both pass through firewalls, and they both provide stateless and connectionless communication between machines. These two technologies share many of the same principles.
It is important to recognize that Microsoft has merged the functionality of remoting, Web services, enterprise services, and MSMQ (Microsoft Message Queue) into the Windows Communication Foundation (WCF)the next generation of the technologies. You can find more information on WCF in Chapter 32.
When working with XML Web Services, you will find that the biggest problem with SOAPSimple Object Access Protocolis that it is not lightweight. It is designed with maximum platform interoperability in mind, and this puts certain limits on how data can be transferred. For example, imagine that Platform A stores Integer variables as a 4-byte block of memory, with the lowest-value byte appearing first. Now imagine that Platform B also uses a 4-byte block of memory, but this time the highest-value byte appears first. The encoding of the value is different. Without some form of conversion, if you copy that block of bytes from Platform A to Platform B, the platforms will not be able to agree on what the number actually is. In this scenario, one platform thinks it has the number 4, whereas the other thinks that the number is actually 536870912.
Integer
4
536870912
SOAP gets around this problem by representing numbers (and everything else) as strings of ASCII characterssince ASCII is a text-encoding standard that most platforms can understand. However, this means that the native binary representations of the numbers have to be converted to text each time the SOAP document has to be constructed. In addition, the values themselves have to be packaged in something that you can read (with a little bit of effort). This leads to two problems: massive bloat (a 4-byte value starts taking hundreds of bytes to store) and wasted CPU cycles used in converting from native encoding to text encoding and back again.
You can live with all these problems if you only want to run your web service on, say, Windows 2000, and have it accessed through a client running on a cell phone. SOAP is designed to do this kind of thing. However, if you have a Windows XP desktop application that wants to use objects hosted on a Windows 2000 server (using the same platform), the bloated network traffic and wastage in terms of conversion is sub-optimal at best and ridiculous at worst.
Remoting enables you to enjoy the power of Web services but without the downside. If you want, you can connect directly to the server over TCP and send binary data without having to do any conversions. If one Windows computer has a 4-byte block of memory holding a 32-bit integer value, you can safely copy the bit pattern to another Windows computer and both will agree on what the number is. In effect, network traffic sanity is restored and processor time is not wasted doing conversions.
Now that you know what remoting is, you’re ready to look at its architecture.
Chapter 25 explored the vast hinterland of legacy software known as COM. This chapter looks at “what COM did next” and how... more
Chapter 25 explored the vast hinterland of legacy software known as COM. This chapter looks at “what COM did next” and how it fits into the world of .NET, in the form of .NET Enterprise Services.
To understand Enterprise Services, you must go back in time (all the way to the last century!) when a number of technologies began to emerge from Microsoft, including Microsoft Transaction Server (MTS), Microsoft Message Queuing (MSMQ), and Microsoft Clustering Services. The aim of these developments was to increase the scalability, performance, and reliability of applications.
Handling transactions involved a considerable extension to the NT/COM runtime. It also involved the introduction of several new standard COM interfaces, some to be used or implemented by transactional components and some to be used or implemented by the underlying resource managers, such as SQL Server. These additions, along with some other innovations relating to areas such as asynchronous COM, came to be known as COM +.
This chapter explores the .NET Enterprise Services. In particular, it looks at transaction processing and queued components using the classes of the System.EnterpriseServices and System.Transactions namespaces. This is an enormous subject that could easily fill a whole book by itself, so this chapter only scratches the surface of it. However, by the end of the chapter, you will understand how all the pieces fit together. Let’s begin by looking at what transactions are, and how they fit into Visual Basic 2008.
System.EnterpriseServices
System.Transactions
Just as it is difficult to live your life without talking with people, your applications also need to communicate, perhaps... more
Just as it is difficult to live your life without talking with people, your applications also need to communicate, perhaps with other programs or perhaps with hardware devices. As you have seen throughout this book, you can use a variety of techniques to have your program communicate, including .NET Remoting, Web Services, and Enterprise Services. This chapter looks at yet another way to communicate: using the basic protocols on which the Internet and many networks have been built. You will learn how the classes in System.Net can provide a variety of techniques for communicating with existing applications such as web or FTP servers, or how you can use them to create your own network applications.
System.Net
Before getting started on writing applications using these classes, however, it would be good to get some background on how networks are bolted together, and how machines and applications are identified.
Until now, building components that were required to communicate a message from one point to another was not always the simplest... more
Until now, building components that were required to communicate a message from one point to another was not always the simplest of tasks. This was because Microsoft provided more than one technology that you could have used for such an action.
For instance, you could have used ASP.NET Web Services, Web Service Enhancements 3.0 (WSE), MSMQ, Enterprise Services, .NET Remoting, and even the System.Messaging namespace. Each one of these technologies has pros and cons associated with it. ASP.NET Web Services (also known as ASMX Web Services) provided the capability to easily build interoperable Web services. The WSE enabled you to easily build services that took advantage of some of the WS-* message protocols. MSMQ enabled the queuing of messages, making it easy to work with solutions that were only intermittently connected. Enterprise Services, provided as a successor to COM+, offered an easy means to build distributed applications. .NET Remoting provided a fast way to move messages from one .NET application to another. Moreover, this is only the Microsoft worldit does not include all the options available in other environments, such as the Java world.
System.Messaging
With these options for a Microsoft developer alone, it can be tough to decide what path to take with the applications you are trying to build. With this problem in mind, Microsoft has brought forth the Windows Communication Foundation (WCF).
WCF is a framework for building service-oriented applications. Microsoft wanted to provide its developers with a framework that would provide the fastest means to getting a proper service-oriented architecture up and running. Using the WCF, you can take advantage of all of the items that made the aforementioned distribution technologies powerful. WCF is the answer and the successor to all these other message distribution technologies.
WCF was introduced as a new component with the .NET Framework 3.0 release. Therefore, to work through the examples in this chapter, you need at least the .NET Framework 3.0 installed on your machine.
Modern, multitasking operating systems often need to run applications that operate in the background and that are independent... more
Modern, multitasking operating systems often need to run applications that operate in the background and that are independent of the user who is logged in. From Windows NT to Windows Vista, such applications are called Windows Services (formerly known as NT Services). The tasks carried out by Windows Services are typically long-running tasks and have little or no direct interaction with a user (so they don’t usually have user interfaces). Such applications may be started when the computer is booted and often continue to run until the computer is shut down.
This chapter covers the following:
The characteristics of a Windows Service
How to interact with a Windows Service using Visual Studio 2008 and the management applets in the Windows Control Panel
How to create, install, and communicate with a Windows Service using Visual Basic
How to debug a Windows Service from within Visual Studio 2008
As VB6 did not offer direct support for the creation of Windows Services, you might be unfamiliar with such applications. To help you understand the variety of such applications, this chapter examines some scenarios for which a Windows Service application is a good solution.
In today’s network-centric world, it is very likely that applications will need to work with other computers over a private... more
In today’s network-centric world, it is very likely that applications will need to work with other computers over a private network, the Internet, or both. This chapter details how to do the following:
Download resources from the Web
Design your own communication protocols
Reuse Internet Explorer in your applications
When the .NET Framework was first introduced, one nice addition for the Visual Basic developer was the inclusion of a standalone... more
When the .NET Framework was first introduced, one nice addition for the Visual Basic developer was the inclusion of a standalone language compiler. This meant you were not required to have the Visual Studio .NET 2002 IDE in order to build Visual Basic applications. In fact, you could take the .NET Framework from the Microsoft website (free of charge), and build Web applications, classes, modules, and more simply, using a text editor such as Notepad. You could then take the completed files and compile them using the Visual Basic compiler.
The Visual Basic compiler is included along with the default .NET Framework install. Each version of the framework has a new compiler. In fact, note that while the core of the .NET 3.5 release is still running on the .NET Framework 2.0, the .NET Framework 3.5 release includes new compilers for both the Visual Basic and C# languages. The compiler for the .NET Framework 2.0 is vbc.exe, and it can be found at
vbc.exe
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe
The compiler for the .NET Framework 3.5 is also called vbc.exe, and it can be found at
C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe
This appendix takes a look at the Visual Basic Power Packs Tools. These tools are a set of off-cycle release packages that... more
This appendix takes a look at the Visual Basic Power Packs Tools. These tools are a set of off-cycle release packages that focus on helping developers who are maintaining traditional Visual Basic 6.0 applications begin the process of transitioning to Visual Basic .NET. Additionally, they contain a set of features intended for developers with years of Visual Basic experience to replicate tasks and behaviors that were easy in Visual Basic 6.0 in Visual Basic .NET.
This appendix briefly examines the two installation packages that are currently available. These packages were released targeting Visual Studio 2005, but they are fully compatible with Visual Studio 2008. Moreover, elements of the Visual Basic Power Packs 2.0 package for printing have been fully integrated with, and ship as part of, Visual Studio 2008. It is hoped that additional portions of this package will be included in Visual Studio 2008 as part of a future update such as a service pack.
This appendix focuses on three areas:
Power Packs background, including goals and installation
The Interop Forms Toolkit 2.0
The Visual Basic Power Packs 2.0
These tools are available as free downloads; however, due to licensing restrictions on the Express Editions, Visual Basic Express and the other Express Editions do not support any add-ins. Thus, to leverage the Power Packs you need a licensed version of Visual Studio Standard or above. Why you would want to leverage the Power Packs is a question best answered by understanding the issues that the Power Packs address. These aren’t just technology for technology’s sake: They address very real issues that traditional VB developers are facing today.
This appendix provides a short list of VB resources available.... more
This appendix provides a short list of VB resources available.
Purchase Before purchasing this product, please be sure you have met all software and system requirements, and that you understand any limits placed upon its use.
Return Policy Wrox Chapters on Demand are