Objective 1.02: .NET Framework


The .NET Framework is the key technology that defines .NET. It is an application environment for building, deploying, and running .NET applications. The .NET Framework consists of the following two components:

  • Common Language Runtime (CLR) The environment that manages the code during runtime

  • Base Class Library (BCL) A huge collection of managed code classes that provide essential services to applications developed in .NET

In this section, we will examine the services provided by the .NET Framework more closely.

Understanding the .NET Framework

The .NET Framework is an extensive collection of classes that is accessible by all .NET programming languages. In fact, .NET ships with over 3,000 classes in the framework. These classes, known collectively as the Base Class Library (BCL), provide a core set of data types, events, exceptions, interfaces, and attributes to applications, as well as components that provide a database, a user interface, a file system, a network, a remote application, and security services.

Framework classes are organized into related groups called namespaces. In order for an application to be able to access a class, it has to first access the related namespace. In this manner, two classes can have the same name as long as they exist in different namespaces. Namespaces can themselves be organized into hierarchies that can be several levels deep.

Only two top-level namespaces ship natively with .NET—Microsoft and System. The Microsoft namespace provides application compilation and code generation services for three of the Microsoft programming languages: Visual C#, Visual Basic, and JScript. It also provides access to Windows-specific components, such as events and the system registry.

The System namespace contains the fundamental classes to support .NET. Dozens of classes exist directly under the System namespace (such as Object and String), while thousands more exist in the namespaces beneath the System namespace.

There are about twenty built-in data types in .NET. Since the BCL defines this standard set of types, components written in one language that wish to define a string can easily pass that string to components written in other languages that are expecting a string. Because there are so many ways of creating strings in an unmanaged environment, programs often have to perform some conversion routines on the string before passing it to a component written in another programming language.

The BCL also defines a number of web classes collectively known as ASP.NET. These classes live in the System.Web namespace. ASP.NET classes allow developers to create web-based applications, which are accessed primarily using a web browser. With ASP.NET, developers can create web applications in any .NET programming language of their choice, with better performance due to just-in-time (JIT) compiling and a new server-side control model that provides a clean separation of content and behavior. Whereas old ASP applications often intermixed HTML and ASP code, ASP.NET code is often completely separate from the HTML web pages it acts on.

The BCL provides a core set of data access classes known as ADO .NET. These classes live in the System.Data namespace. ADO .NET provides efficient, object-oriented access to databases similar to the way ADO COM objects did under the Windows DNA programming model. However, ADO .NET classes focus on disconnected recordsets (called datasets in the .NET paradigm), which means that applications do not have to keep connections open to the database while they are analyzing and modifying data.

There are also .NET Framework classes for handling XML that lives in the System.XML namespace. The BCL includes an XML parser and support for other XML technologies such as Extensible Stylesheet Language Transformation (XSLT).

Assemblies

Applications or components written in one of the .NET programming languages are compiled into assemblies. An assembly is a binary file formatted in Microsoft Intermediate Language (MSIL). Theoretically, once a program has been compiled from source code into an assembly, it should be impossible to determine what the original programming language was. Identical programs written in different programming languages should compile to almost the same assembly code.

On The Job

MSIL is an abstract language that is not closely related to any particular brand of operating system or CPU. This means that .NET assemblies do not contain code specific to Microsoft Windows or the Intel Pentium processor.

Assemblies contain both the MSIL code and some related metadata. Metadata is “data about data,” and the assembly metadata lists the names of the external components the code relies on, as well as the exposed property and method names. COM components also contained some metadata (called a type library), but the assembly metadata is much more complete. Programmers can even add their own metadata to provide other applications more information on how and when to use the component.

The metadata also enables the improved versioning capabilities discussed earlier in this chapter (see “Why is .NET Better Than COM/DCOM?”). .NET ensures that applications are linked to components with the correct version number and that a new version of a component can be installed on a system without interfering with an older version of the same component.

The Common Language Runtime (CLR)

The Common Language Runtime (CLR) is a runtime environment for executing .NET applications. That means that the CLR sits between the .NET program code and the operating system, managing the interaction between the two. That is why .NET applications are often called managed code. Code that executes outside the .NET environment is often called unmanaged code.

The CLR loads the .NET assemblies into memory and compiles them into binary executables specific to the local CPU. This process is called just-in-time (JIT) compiling. This distinguishes the CLR from the Java Virtual Machine (JVM) in that the JVM is a bytecode interpreter. Compiled languages are generally faster than interpreted ones.

The CLR provides two great benefits to .NET developers:

  • All .NET languages are fairly equal in terms of performance, so the choice of programming language becomes one of developer preference rather than suitability to task.

  • Applications written in one language can seamlessly use components created in another, which is sometimes called language interoperability.

The one exception to the performance rule is Visual C++ .NET with Managed Extensions (Managed C++). Managed C++ allows managed and unmanaged code to exist in the same application. You can use the unmanaged code for low-level, performance-critical code and the managed code to access .NET framework classes and components. Examples of performance-critical code would be things like video games, movie-editing software, and other CPU-intensive tasks.

Because the .NET-managed environment adds a small amount of processing overhead and a few restrictions on direct access to certain system resources, software programs that require a lot of processing power or direct access to certain resources will probably continue to be created outside the .NET environment.

On The Job

Although Microsoft claims that the CLR enables applications written in any .NET language to have similar performance, there are still some performance considerations. For instance, when Microsoft converted DirectX to Visual C# .NET, it noticed a 40 percent drop in overall performance. But when that same application was converted to Visual C++ .NET, the performance was nearly equal to the original. This is because Visual C++ applications can directly access the operating system, unlike other programming languages in the .NET environment.

Choosing a .NET Project Template

Microsoft .NET supports several different application types. There are Windows Forms applications, which run directly on a PC running Windows. There are also Web Forms applications, which run inside a web browser over a network. And then there are web services, which are accessible using other applications over a network. Each of these applications is slightly different than the others in .NET. They each use a different set of .NET Framework class libraries and require a different set of support files within Visual Studio. In the case of web-based applications, they require a .NET-compatible server, such as Internet Information Server (IIS), to develop and deploy the applications.

In all, there are eight project templates available in Visual Studio .NET to assist developers with creating new projects:

  • Windows Application

  • ASP.NET Web Application

  • ASP.NET Web Service

  • Console Application

  • Windows Service

  • Class Library

  • Windows Control Library

  • Web Control Library

These templates, along with two or three empty project templates, can be created using either Visual Basic or Visual C# in the Visual Studio .NET environment. Each language has its own unique set of project templates, and some of those templates may not be available in other languages. For instance, developers who code in Visual C++ .NET have the opportunity to create Microsoft Foundation Class (MFC), Active Template Library (ATL), and Managed C++ projects. (Don’t throw away those MFC books just yet.)

  • A Windows application is your basic type of application. This application is designed to have a user interface and runs directly in the Windows environment as a stand-alone application. Windows applications can also access database services, consume web services, and communicate with remote applications across a network.

  • An ASP.NET web application is your traditional web-based application that runs on a web server and is accessible through a browser. Since this web application communicates using the HTML standard over the Internet, it is generally accessible using any browser.

  • An ASP.NET web service is a new type of web-based application that communicates through the XML and SOAP standards. This application provides a service that is accessible by other applications, such as providing currency exchange rates or stock quotes.

  • A console application is a command-line application that is designed to run inside a Windows command prompt (sometimes also called a DOS box). This application is restricted by the command prompt’s text-based user interface. Console applications communicate with the user using text only—there are no dialog boxes, menus, or buttons. The command prompt can be accessed in Windows XP by selecting Run from the Windows Start menu, typing cmd, and clicking the OK button.

  • A Windows service is a Windows application that does not have a user interface. This type of application typically performs behind-the-scenes tasks and is the most hidden from the user of any type of application. Services can be designed to start automatically, every time the operating system starts up, and they typically stay running until the computer is shut down. For instance, antivirus software usually installs itself as a Windows service and runs invisibly in the background while you’re working. Sometimes a service creates an icon in the system tray, but usually it does not.

  • A class library is a reusable class or component that can be shared with other .NET applications. For instance, the .NET Framework contains thousands of class libraries that are accessible by any application that runs in the .NET environment.

  • The Windows Control Library and Web Control Library projects allow developers to create custom controls (buttons, text boxes, and so on) that can be used in Windows or web applications, respectively.

Each of the preceding eight project templates helps you by initializing the development environment with some standard files, code, and project configuration settings. For instance, if you use the ASP.NET Web Service project template, you will start off with a number of default files with which to begin creating your web service.

In addition to the programming language–related templates, there are a few project design, testing, and deployment-related templates in Visual Studio .NET. These templates may or may not be available in your copy of Visual Studio because their availability depends on the edition of Visual Studio you are using and the options that were selected when it was installed:

  • Setup Project A Windows Installer project, making application deployment via CD or the web easier

  • Database Project A project allowing direct manipulation of database objects and data

  • Enterprise Templates A set of complex project templates for large enterprise applications

  • Visual Studio Analyzer Project A project that helps with performance tuning

  • Visual Studio .NET Add-Ins Build add-in tools for the Visual Studio environment

  • Application Center Test (ACT) Project A project designed to stress-test web servers and analyze performance bottlenecks

As you can see, Visual Studio .NET is a rich and expandable environment for developing both simple and complex projects within the .NET environment. There are many project templates, and as companies begin to standardize on their own architecture they will develop custom templates of their own.

Scenarios & Solutions

What applications are designed to run inside a Windows GUI?

Windows Forms applications

What applications are designed to run inside a web browser?

Web Forms applications

What applications use XML and SOAP to communicate with other applications?

Web services applications

What applications are designed to run inside a Windows command prompt?

Console applications




MCSD Analyzing Requirements and Defining. NET Solutions Architectures Study Guide (Exam 70-300)
MCSD Analyzing Requirements and Defining .NET Solutions Architectures Study Guide (Exam 70-300 (Certification Press)
ISBN: 0072125861
EAN: 2147483647
Year: 2003
Pages: 94

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net