- The .NET Framework
- Visual Studio 2005
What’s required to create good software? While it’s possible to write first-rate code in almost any environment, creating good software is much easier when the right platform and tools are available. For most Windows developers today, that platform is defined by .NET. While defining .NET clearly was once a challenge, it’s now clear that the .NET label refers primarily to two things. They are:
- The .NET Framework, which consists of the Common Language Runtime (CLR) and the .NET Framework class library. The CLR provides a standard foundation for building applications, while the .NET Framework class library offers a large set of standard classes and other types that can be used by any .NET Framework application written in any language.
- Visual Studio, an integrated development environment (IDE) for creating Windows applications. While this tool can be used to build software that runs directly on Windows, its main focus is helping developers create .NET Framework applications. Visual Studio supports several programming languages for creating these applications, including C#1, Visual Basic (VB), and C++.
Various versions exist for both of these technologies. The versions described in this book are those released by Microsoft in late 2005: version 2.0 of the .NET Framework and Visual Studio 2005.
The .NET Framework
The heart of .NET is the .NET Framework. First released in 2002, it brought enormous change to the lives of those who write Windows software and the people who manage them. Figure 1-1 shows the Framework’s two main parts: the CLR and the .NET Framework class library. A .NET application always uses the CLR, and it can also use whatever parts of the class library it requires.
Every application written using the Framework depends on the CLR. Among other things, the CLR provides a common set of data types, acting as a foundation for C#, VB, and all other languages that target the .NET Framework. Because this foundation is the same no matter which language they choose, developers see a more consistent environment.
Figure 1-1 The .NET Framework consists of the Common Language Runtime (CLR) and the .NET Framework class library.
Surveying the Library
The contents of the .NET Framework class library are organized into a tree of namespaces. Each namespace can contain types, such as classes and interfaces, and other namespaces. Figure 1-4 shows a very small part of the .NET Framework class library’s namespace tree. The namespaces shown include the following:
Figure 1-4 The .NET Framework class library is structured as a hierarchy of namespaces, with the System namespace at the root.
- System: The root of the tree, this namespace contains all of the other namespaces in the .NET Framework class library. System also contains the core data types used by the CLR (and thus by languages built on the CLR). These types include several varieties of integers, a string type, and many more.
- System.Web: This namespace contains types useful for creating Web applications, and like many namespaces, it has subordinate namespaces. Developers can use the types in System.Web.UI to build ASP.NET browser applications, for example, while those in System. Web.Services are used to build ASP.NET Web Services applications.
- System.Data: The types in this namespace comprise ADO.NET. For example, the Connection class is used to establish connections to a database management system (DBMS), while an instance of the DataSet class can be used to cache and examine the results of a query issued against that DBMS.
- System.Windows.Forms: The types in this namespace make up Windows Forms, and they’re used to build Windows GUIs. Rather than relying on language-specific mechanisms, such as the older Microsoft Foundation Classes (MFC) in C++, .NET Framework applications written in any programming language use this common set of types to build graphical interfaces for Windows.
- System.EnterpriseServices: The types in this namespace provide services required for some kinds of enterprise applications. Implemented by COM+ in the pre-NET world, these services include distributed transactions, object instance lifetime management, and more. The most important type in this namespace, one from which classes must inherit to use Enterprise Services, is the ServicedComponent class.
- System.XML: Types in this namespace provide support for creating and working with XML-defined data. The XmlDocument class, for instance, allows accessing an XML document using the Document Object Model (DOM). This namespace also includes support for technologies such as the XML Schema definition language (XSD) and XPath.
Many more namespaces are defined, providing support for file access, serializing an object’s state, remote access to objects, and much more. In fact, the biggest task facing developers who wish to build on the .NET Framework is learning to use the many services that the library provides. There’s no requirement to learn everything, however, so a developer is free to focus on only those things relevant to his or her world. Still, some parts will be relevant to almost everybody, and so the next sections provide a quick overview of some of this large library’s most important aspects.
Building Web Applications: ASP.NET
Implemented in the System.Web namespace, ASP.NET is an important piece of the .NET Framework. The successor to the very popular Active Server Pages (ASP) technology, ASP.NET applications are built from one or more pages. Each page contains HTML and/or executable code, and typically has the extension .aspx. As Figure 1-5 shows, a request from a browser made via HTTP causes a page to be loaded and executed. Any output the page creates is then returned to the browser that made the request.
Building effective Web applications requires more than just the ability to combine code with HTML. Accordingly, ASP.NET provides a range of support, including the following:
- Web controls, allowing a developer to create a browser GUI in a familiar way. By dragging and dropping standard ASP.NET controls for buttons and other interface elements onto a form, it’s possible to build GUIs for Web applications in much the same way as for local Windows applications.
Figure 1-5 ASP.NET allows developers to create browser-accessible applications.
- Mechanisms for managing an application’s state information.
- Built-in support for maintaining information about an application’s users, sometimes called membership information.
- Support for data binding, which allows easier access to information stored in a DBMS or some other data source.
Given the popularity of Web applications, ASP.NET probably impacts more developers than any other part of the .NET Framework class library. Chapter 5 provides more detail on this key component of the .NET Framework.
Accessing Data: ADO.NET
ADO.NET lets applications work with stored data. As Figure 1-6 shows, access to a DBMS relies on a .NET Framework data provider, written as managed code. Providers that allow access to SQL Server, Oracle, and other DBMS are included with the .NET Framework. They allow a client application to issue commands against the DBMS and examine any results those commands return. The result of a Structured Query Language (SQL) query, for example, can be examined in two ways. Applications that need only read the result a row at a time can do this by using a DataReader object to march through the result one record at a time. Applications that need to do more complex things with a query result, such as send it to a browser, update information, or store that information on disk, can instead have the query’s result packaged inside a DataSet object.
ADO.NET lets applications access stored data
Figure 1-6 ADO.NET allows .NET Framework applications to access data stored in DBMS and XML documents.
As Figure 1-6 illustrates, a DataSet can contain one or more tables. Each table can hold the result of a different query, so a single DataSet might potentially contain the results of two or more queries, perhaps from different DBMS. In effect, a DataSet acts as an in-memory cache for data. As the figure shows, however, DataSets can hold more than just the result of a SQL query. It’s also possible to read an XML document directly into a table in a DataSet without relying on a .NET Framework data provider. Data defined using XML has also become much more important in the last few years, so ADO.NET allows accessing it directly. While not all .NET Framework applications will rely on ADO.NET for data access, a large percentage surely will. ADO.NET is described in more detail in Chapter 6.
Building Distributed Applications
Creating software that communicates with other software is a standard part of modern application development. Yet different applications have different communication requirements. To meet these diverse needs, the .NET Framework class library includes three distinct technologies for creating distributed applications. Figure 1-7 illustrates these choices.
ASP.NET Web Services, mostly defined in System.Web.Services, allows applications to communicate using Web services. Since it’s part of ASP.NET, this technology lets developers use a similar model for creating distributed software. As Figure 1-7 shows, applications that expose methods as Web services can be built from files with the extension .asmx, each of which contains only code. Clients make requests using the standard Web services protocol SOAP2, and the correct page is loaded and executed. Because this technology is part of ASP.NET, requests and replies also go through Internet Information Services (IIS), the standard Web server for Windows.
Figure 1-7 Distributed applications can use ASP.NET Web Services, .NET Remoting, or Enterprise Services.
Communication via Web services is especially useful for interoperating with software built on platforms other than the .NET Framework, such as the Java environment. But it’s not always the right solution. In some situations, the technology known as .NET Remoting, defined in the System.Runtime.Remoting namespace, is a better choice. Unlike ASP.NET Web Services, .NET Remoting focuses on direct communication between applications built on the .NET Framework. While it does support a version of SOAP, this technology also provides a binary protocol along with the ability to add extensions using any other protocol a developer needs. .NET Remoting isn’t the most common choice for communication, but it can be important for some kinds of applications.
The third option for creating distributed applications using the .NET Framework is Enterprise Services. Defined in the System.EnterpriseServices namespace, it provides applications with services such as distributed transactions and more. Figure 1-7 illustrates this, showing a server application accessing two databases. If a single transaction included updates to both of these databases, Enterprise Services might well be the right choice for the application that used this transaction. Remote clients can communicate directly with an Enterprise Services application using DCOM, and it’s also possible for an ASP.NET application to use Enterprise Services when necessary.
All three options make sense in different situations, and having a basic understanding of all three is useful. For a more detailed look at each of them, see Chapter 7.