According to MicroSoft, The .NET platform is an integral component of the Microsoft Windows operating system for building and running next generation software applications and Web services. The .NET development framework provides a new and simplified model for programming and deploying applications on the Windows platform. It provides such advantages as multi platform applications, automatic resource management, and simplification of application deployment. As security is an essential part of .NET, it provides security support, such as code authenticity check, resources access authorizations, declarative and imperative security, and cryptographic security methods for embedding into the user’s application.
.NET provides a simple object-oriented model to access most of the Windows application programming interfaces (APIs). It also provides mechanisms by which we can use the existing native code. In addition, it significantly extends the development platform by providing tools and technologies to develop Internet-based distributed applications.
The .NET Platform
The Microsoft .NET platform, as illustrated in Figure 1.1 and described as follows, consists of four components:
.NET Framework. The .NET Framework is a multi language, application execution environment that transparently manages core infrastructure services. It is a set of multiple languages/technologies used for developing and creating components to create Web Forms, Web services, and Windows applications. It supports the software life cycle for development, debugging, deployment, and maintenance of applications. The version of .NET framework that ships with Visual Studio .NET 2003 is version 1.1. The .NET Framework consists of the following parts (also depicted in Figure 1.2):
.NET Framework. The .NET Framework is a multi language, application execution environment that transparently manages core infrastructure services. It is a set of multiple languages/technologies used for developing and creating components to create Web Forms, Web services, and Windows applications. It supports the software life cycle for development, debugging, deployment, and maintenance of applications. The version of .NET framework that ships with Visual Studio .NET 2003 is version 1.1. The .NET Framework consists of the following parts (also depicted in Figure 1.2):
-
- Common Language Runtime (CLR).
- .NET Framework base class library.
- Common Language Specification (CLS).
- .NET-compliant languages.
- Data and XML classes such as ADO.NET and XML.
- A set of class libraries for building XML Web services.
- ASP.NET Web Forms-based Web applications.
- Windows Forms-based rich client applications.
- Common Type System (CTS).
- Microsoft Visual Studio .NET 2003 integrated development environment (IDE).
- Development tools. Microsoft provides the programming model, the development environment, and the tools necessary to build, deploy, and operate Web services with applications such as Visual Studio .NET 2003.
- .NET enterprise servers. The Microsoft .NET enterprise servers make up the Microsoft .NET server infrastructure for deploying, managing, and operating XML Web services and traditional applications. Examples of enterprise servers are Microsoft SQL Server™ 2000 and Microsoft Commerce Server 2000.
- .NET foundation services. A core set of building block services that execute standard tasks and act as a basis for developers to build upon. These foundation services are known as Microsoft .NET My Services and provide many features and functions. Most of the foundation services are hosted (outsourced) services. An example of a currently available Web service is Microsoft .NET Passport.
Advantages of .NET
The .NET Framework provides the following advantages:
A consistent, object-oriented programming environment.
A consistent, object-oriented programming environment.
- A code-execution environment that:
- Promotes safe execution of code.
- Eliminates the performance problems of scripted or interpreted environments.
- Minimizes software deployment and versioning conflicts.
- A consistent experience for both developers and users across various types of Windows-based and Web-based applications on multiple devices.
- Communication built on the industry standards to ensure that code based on the .NET Framework can integrate with any other code.
.NET is based on open Internet standards, which include Hypertext Transfer Protocol (HTTP), Extensible Markup Language (XML), and Simple Object Access Protocol (SOAP).
Figure 1.2 depicts the overall architecture of the .NET Framework components.
Features of the .NET Framework
This section discusses some of the features of the Microsoft .NET Framework and how to use these features in migrating code from the UNIX environment.
Common Language Runtime (CLR)
The core of the .NET Framework is the CLR, the run-time environment provided by .NET. The runtime manages code at execution time and provides core services such as memory management, thread management, remoting, and strict type safety enforcement.
CLR Features
UNIX applications, redeveloped on .NET, can make use of all the features provided by the CLR, including:
- Simplified development and deployment of applications.
- Application memory management.
- Improved performance, scalability, and reliability.
- Cross-language inheritance.
- Multiple language support.
- Automatic garbage collection.
- Security.
- Strong type checking.
- Access to type metadata.
- Unified exception handling.
- Interoperability with existing code in COM (Component Object Model) objects and Microsoft Win32® DLLs.
- Loading and executing code.
- Just-in-time (JIT) compilation of Microsoft intermediate language (MSIL) to native code.
- Side-by-side execution for multiple assembly versions.
- Other developer support services that include debugging and run-time profiling.
- Versioning and deployment support.
The .NET runtime also enforces other forms of controlled code access that promote security and robustness. Code management is a fundamental principle of the runtime. Code that targets the CLR is known as managed code, whereas code that does not target the CLR is known as unmanaged code. Unmanaged code can also be used in the .NET environment using interoperability techniques.
All .NET applications compile to a common language called MSIL. A JIT compiler then compiles MSIL to optimized native code.
Benefits of CLR
The various benefits offered by the CLR are as follows.
Security
The runtime enforces code access security. The managed components have varying degrees of trust level depending on a number of factors, including their origin. Even if the same active application is using the managed component, depending on the trust level, the managed component might or might not be capable of performing file-access operations, registry-access operations, or other sensitive functions.
For example, users can trust that an executable embedded in a Web page can play an animation or a song, but cannot access their personal data, file system, or network.
Code Robustness
The runtime also enforces code robustness by implementing a strict type-and-code-verification infrastructure called the Common Type System (CTS). The CTS ensures that all managed code is self-descriptive. The various Microsoft and third-party language compilers generate managed code that conforms to the CTS.
Developer Productivity
The runtime also accelerates developer productivity by enabling the developers to write applications in the development language of their choice and still take advantage of all the features of the runtime. The language compilers that target the .NET Framework make the features of the .NET Framework available to the existing code written in that language, thus greatly facilitating the migration process for the existing applications.
Performance
The runtime is designed to enhance performance. JIT compiling enables all managed code to run in the native code of the system on which it is executed. At the same time, the memory manager removes the possibilities of fragmented memory and increases the memory locality-of-reference to improve the performance further.
Interoperability
The runtime, although designed for modern software, also offers backward compatibility by supporting older software. Interoperability between managed and unmanaged code provides seamless integration to developers to continue to use necessary COM objects and exported functions in unmanaged DLLs.
.NET Framework Base Class Library
The Microsoft .NET Framework 1.1 base class library is an object-oriented class library providing an integrated set of classes that expose the underlying functionality of the Win32 API as well as some other additional capabilities. These classes integrate tightly with the CLR. Third-party components can also integrate with the classes in the .NET Framework. In the Microsoft .NET library, all classes (types) are grouped in namespaces. A namespace is a grouping of similar kinds of classes.
The .NET Framework classes enable us to perform a range of common programming tasks such as string management, data collection, database connectivity, and file access. In addition to these common tasks, the class library includes classes that support a variety of specialized development functions. For example, we can use the .NET Framework to develop a variety of applications such as console applications, GUI (graphic user interface) applications, and Web applications.
All .NET languages can use these language-independent classes. This enables the programmers to choose the language and tools best suited for the job or the language with which they have the most experienced and still share their code and create new subclasses from classes written in a different language. This code reuse can dramatically increase team productivity and decrease development costs. Figure 1.4 depicts some of the namespaces and their classes in the .NET Framework.
.NET Tools and Technologies
From a migration perspective, .NET provides various tools and technologies that help we to migrate or redevelop a UNIX application on Windows. Some of these tools and technologies are discussed in the following sections.
Database - ADO.NET
.NET provides ADO.NET for migrating the database-related components of a UNIX application to .NET. ADO.NET is a collection of classes, structures, and interfaces that manage data access for different databases. .NET provides this data access technology to enable us to connect to different databases including ODBC-aware (open database connectivity) databases.
Networking - System.NET
The System.NET namespace in .NET allows us to replicate the networking functionality of a UNIX application on Windows.
Transaction - COM+ Services
.NET provides COM+ services, also referred to as Enterprise Services in .NET, to migrate applications that involve a large amount of transactions.
Rich Client - Windows Forms
Windows Forms enable us to replicate the X/Motif-based GUI of a UNIX application on Windows. Windows Forms facilitate the building of Windows rich-client applications that take advantage of the CLR. The Visual Studio .NET 2003 IDE also aids in the rapid redevelopment of GUI on Windows with the same look and feel as in UNIX.
Web Applications - ASP.NET
.NET provides Web Forms and ASP.NET for migrating the existing Web application on UNIX to Windows. Web Forms and ASP.NET enable us to develop real-world Web applications on Windows.
Application Integration - XML, SOAP, and Web Services
.NET supports XML, SOAP, Web services, and .NET servers that enable a migrated application to integrate with the older applications and other applications in our enterprise.
.NET XML Framework
This section lists the XML APIs available in the .NET class library that we can use for various XML-related operations.
XML is truly a core technology substrate in .NET. All other parts of the .NET Framework (such as ASP .NET and Web services) use XML as their native data representation format. The .NET Framework XML classes are also tightly coupled with Managed Data Access (ADO .NET). Traditionally, there have always been different programming models for working with relational and hierarchical data. .NET breaks that tradition by offering a more deeply integrated programming model for all types of data.
New Suite of XML APIs
Microsoft .NET introduces a new suite of XML APIs built on such industry standards as Document Object Model (DOM), XPath, XML Structured Definitions (XSD), and Extensible Stylesheet Language Transformations (XSLT). The .NET Framework XML classes offer convenience and better performance. The .NET XML Framework also provides a more familiar programming model, tightly coupled with the various classes present in System.Data and System.Xml namespaces, which encapsulate a number of functionalities that previously had to be accomplished manually.
.NET XML Namespaces
The System.Xml assembly contains a broad range of general-purpose XML support features, such as:
- Basic I/O model.
- I/O of primitive types.
- In-memory traversal.
- Filtering based on XPath expressions.
- Transformations based on XSLT.
The .NET XML stack is partitioned over several namespaces, such as:
- System.Xml.XPath
- System.Xml.Xsl
- System.Xml.Schema
- System.Xml.Serialization
XML-based I/O
All XML-based I/O is performed using a streaming interface suite as follows:
- Streams are supported in both pull-mode (read) and push-mode (write).
- Built-in streaming adapters use the System.IO.Stream class library.
- Abstract interfaces allow you to provide your own XML providers/consumers.
.NET DOM Implementation
The .NET DOM implementation (System.Xml.XmlDocument) supports all W3C DOM Level 1 core and all DOM Level 2 core specifications, but with a few minor naming changes. The DOM loading is built on top of XmlReader, while the DOM serialization is built on XmlWriter. This makes it possible to extend how the DOM interacts with applications in numerous ways.
Transformations
The XslTransform class manages XSLT transformations in the .NET Framework. XslTransform resides in the System.Xml.Xsl namespace and uses XmlNavigator during the transformation process. As with all XSLT processors, XslTransform accepts an XML document, an XSLT document, and some optional parameters as input. It can produce any type of text-based output; it also supports reading the result of the transformation using a custom XmlReader.
.NET Application Security
This section provides an overview of various security models available in the .NET Framework. The .NET Framework provides a rich security system, capable of confining code to run in a tightly constrained, administrator-defined, security context.
Role-based Security
The .NET Framework provides a developer-defined security model called role-based security that attaches securely to the users and their groups (or roles). The principal abstractions of role-based security are principal and identity.
Code Access Security
Additionally, the .NET Framework also provides security on code, referred to as code access security (also referred to as evidence-based security). With code access security, a user may be trusted to access a resource but if the code that the user executes is not trusted, then access to the resource is denied. Code access security also provides a highly protective way of securing the assemblies from malicious attacks. Security based on code, as opposed to specific user, is a fundamental facility that permits security to be expressed on mobile code. Any number of users may download and execute mobile code, which is unknown at the time of development. Code access security focuses on some core abstractions, namely, evidence, policies, and permissions.
The security abstractions for role-based security and code access security are represented as types in the .NET Framework class library and are user-extendable.
The .NET Framework security system functions atop the traditional operating system security. This adds a second, more expressive and extensible level to the operating system’s security. Both layers complement each other. (It is conceivable that an operating system security system can delegate some responsibility to the CLR security system for managed code because the run-time security system is more configurable than the traditional operating system security.)
Implementation in .NET
The following topics give an overview for implementing the following architectural elements in .NET:
- Processes and threads
- Memory management
- File management
- Signals, exceptions, and events
- Networking
- Interprocess communication
- User interface
- Daemons versus services
- Deployment
Processes and Threads
The .NET Framework further divides an operating system process into lightweight managed sub-processes, called application domains, which provide a versatile unit of processing in .NET applications. These application domains are used to provide isolation between applications and even within a single process. Several application domains can be run in a single process with the same level of isolation that would exist in separate processes. Historically, process boundaries have been used to provide isolation between applications, but application domains provide a level of isolation equivalent to that of a process boundary, however at a much lower cost of performance.
The System.Threading namespace in .NET provides all the classes and interfaces necessary to enable multithreaded programming. In addition to classes for synchronizing thread activities and providing access to data (for example, Mutex, Monitor, Interlocked, and AutoResetEvent), this namespace includes a ThreadPool class that allows the use of a pool of system-supplied threads and a Timer class that executes callback methods on the thread pool threads. The next chapters discuss application domains and the threading namespaces in detail.
Memory Management
The garbage collector of the .NET Framework provides automatic memory management. It allocates and releases the memory for managed objects and, when necessary, executes the appropriate methods at the appropriate times in order to properly clean up the unmanaged resources. Automatic memory management simplifies development by eliminating the common bugs that arise from manual memory management schemes.
File Management
In .NET, the System.IO namespace provides an object-oriented tool to work with files and folders. It provides a collection of properties, methods, and events to process text and data, thus enabling us to perform file and directory operations with greater ease.
Signals, Exceptions, and Events
.NET Framework provides an event handler mechanism to handle events. An event handler is a procedure in our code that determines the actions that must be performed when an event (such as the user clicking a button or a message queue receiving a message) occurs. When an event is raised, the event handler (or a handler) that receives the event is executed. Events can be assigned to multiple handlers and the method that handles a particular event can be changed dynamically.
The .NET Framework handles exceptions through the exception handling mechanism. In the .NET Framework, an exception is an object that it inherits from the System.Exception class. An exception originates from an area of code where a problem occurred. The exception is passed up the stack until the application handles it or the program terminates. All .NET languages handle exceptions in a similar manner. Each language uses a form of try/catch/finally structured exception handling.
Networking
The .NET Framework class library includes two namespaces that consist of classes that help us with networking; these are System.Net and System.Net.Sockets.
The System.Net classes provide a simple, yet complete solution for writing networked applications in managed code. The System.Net.Sockets classes deal with the TCP/UDP and sockets.
Interprocess Communication
In the .NET environment, application domains enable more than one application to run within a single process, thus eliminating the overhead of making cross-process calls but still maintaining the same level of application isolation that would exist in separate processes. .NET also supports the concept of thread local storage, by which data can be stored in a thread and accessed anywhere the thread exists.
Microsoft .NET Remoting provides a rich and extensible framework for objects residing in different application domains, in different processes, and indifferent computers to communicate with each other seamlessly. .NET Remoting offers a powerful, yet simple, programming model and run-time support for making these interactions transparent.
User Interface
In the .NET environment, user interfaces can be developed as Windows or WebForms. Some of the advantages of using these forms include the following:
- Simplicity and power
- Rich graphics
- Flexible controls
- The lower total cost of ownership
- Architecture for controls
- High security
- XML Web services support
- Data awareness
- ActiveX control support
- Easy licensing
- Enhanced printing support
- Accessibility
- Design-time support
Daemons vs. Services
The .NET Framework class library includes the System.ServiceProcess namespace provides classes to implement, install, and control Windows service applications.
Services are installed using an installation tool, such as InstallUtil.exe. The System.ServiceProcess namespace provides installation classes that write service information to the registry.
The ServiceController class enables us to connect to an existing service and manipulate it or get information about it. This class is typically used in an administrative capacity; it enables us to start, stop, pause, continue, or perform custom commands on a service.
Deployment
In .NET Framework applications, assemblies are the building blocks. They form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. Current Win32 applications have two versioning problems with their building blocks (dynamic-link libraries):
- Versioning rules cannot be expressed between pieces of an application and enforced by the operating system.
- Inability to maintain consistency between sets of components that are built together and the set that is present at runtime.
These two versioning problems combine to create DLL conflicts, or DLL Hell, were installing one application can inadvertently break an existing application because a certain software component or DLL that was installed was not fully backward compatible with a previous version. The CLR uses assemblies to provide a complete solution for DLL conflicts. Assemblies allow the runtime to:
- Enable developers to specify version rules between different software components.
- Enable the infrastructure to enforce versioning rules.
- Enable the infrastructure to allow multiple versions of a component to run simultaneously (called side-by-side execution).
Each computer, where the CLR is installed, has a machine-wide code cache called the Global Assembly Cache (GAC). The GAC stores assemblies specifically designated to be shared by several applications on the computer.
Assemblies deployed in the GAC must have a strong name. When an assembly is added to the GAC, integrity checks are performed on all files that make up the assembly. The cache performs these integrity checks to ensure that an assembly has not been tampered with.
Platform Invocation Services (P/Invoke)
Platform Invocation services (P/Invoke) enable the managed code to call the C-style functions, which are exposed by the native dynamic-link libraries (DLLs). P/Invoke services provide a direct way of using the C functions from the existing native DLLs in a managed application. P/Invoke services are used in conjunction with the DllImport attribute, which is used to import functions from an unmanaged DLL into a managed application.
As an example, consider a situation where the UNIX code can be migrated to Windows with minimal changes and we need to use this code in a new C# or Visual Basic .NET application or project. After migrating to Windows, we can compile the code into a DLL and call it from any .NET project.
This method provides the following advantages:
- Usage. We can use this method with all .NET languages (C#, Visual Basic .NET, and Managed Extensions for C++). Therefore, new C# or Visual Basic .NET projects can use the DLLImport attribute to connect to the unmanaged code.
- Quick reuse of code. This method enables quick reuse of the existing native code.
However, we may not use this method in the following situation: If a function in the DLL returns an unmanaged string, such as
Note: The line has been split into multiple lines for readability. However, while trying it out on a system we must enter it as one line without breaks.
[DllImport("mylib")]
extern "C" String * MakeSpecial([MarshalAs
(UnmanagedType::LPStr)] String *);
then we will not be able to delete the memory of the unmanaged string that is returned. In such cases, the C++ Interoperability It Just Works (IJW) method described in the next section is the best choice.
The disadvantages of the P/Invoke method are:
- Used with attributes only. Unmanaged APIs cannot be used directly without the use of the DLLImport attribute.
- Memory leakage. This method sometimes causes memory leakages for some C-style functions using unmanaged data types as illustrated by the earlier example.
Web Applications
Web applications from a UNIX Web server are, usually, either a Common Gateway Interface (CGI) or Java Server Page (JSP). The CGI program is a standard for connecting external applications with information servers, such as Web servers.
A CGI program is executed in real time to generate dynamic information. For example, a CGI program on the Web server executes to transmit information to a database engine, retrieves result sets, and displays the result sets to the client browser.
JSP technology also enables the development of dynamic Web pages. JSP technology uses tags and scriptlets written in the Java programming language to encapsulate the logic that generates the content for the page. The application logic resides in server-based resources such as a JavaBean component, which the page accesses by using the tags and scriptlets. Formatting tags such as HTML and XML tags pass directly back to the response page.
.NET provides ASP.NET, a unified Web development model that includes the services necessary for developers to build enterprise-class Web applications. ASP.NET provides Web Forms and Web services. WebForms allow us to quickly build powerful forms-based Web pages. Web services enable the exchange of data using standards such as HTTP and XML messaging to move data across firewalls. XML Web services are not tied to a particular component technology or an object-calling convention. As a result, programs written in any language, using any component model, and running on any operating system can access XML Web services.
If an application uses CGI, then the migration strategy depends on the language in which the program was written. The languages include C/C++, Fortran, Perl, Tcl, UNIX shells, and Microsoft Visual Basic. Many Web developers write CGI programs in Visual Basic language because of its powerful text-handling capability. CGI2ASP is a framework for porting programs written in Visual Basic, using Windows CGI, to a component-based ASP application with virtually no change to the existing Visual Basic-based code.
If an application uses JSP technology, then you need to rewrite the JSP scriptlets (written in Java and residing in JavaBean components) in Microsoft Visual Basic Scripting Edition or Microsoft JScript and contained in ASP COM components. A tool named Java Language Conversion Assistant (JLCA) is also available for use in the Visual Studio .NET 2003 environment; this tool can automatically convert most JSP code to ASP.NET.
Database Applications
When moving the database applications to .NET, the most common migration strategy is to re-engineer the application to use ADO.NET. Through ADO.NET, you can efficiently manage the database interactions in an application.
ADO.NET is an evolution of the Microsoft ActiveX® Data Object (ADO) data access model that directly addresses user requirements for developing scalable applications. ADO.NET was designed specifically for the Web, keeping scalability, statelessness, and XML in mind. The ADO.NET version that comes with Visual Studio .NET 2003 is version 1.1, which is the version used in this guide. A new version of ADO.NET 2.0 has been released with the latest release of Visual Studio .NET 2005.
ADO.NET uses some of the ADO objects, such as the Connection and Command objects, and introduces some new objects, such as DataSet, DataReader, and DataAdapter.
The OLE DB and SQL Server .NET Data Providers (System.Data.OleDb and System.Data.SqlClient), which are part of the .NET Framework, provide five basic objects. These objects are the Connection, Command, DataReader, DataSet, and DataAdapter.
- Connections. Used to connect to the database and manage the transactions against the database.
- Commands. Used to execute the SQL statements against a database.
- DataSets. Allow you to store the database schema and to program against flat data, XML data, and relational data.
- DataReaders. Allow you to read a forward-only stream of data records from a data source.
- DataAdapters. Used as a bridge between the data sources and data sets.
The records are mapped to the given commands accordingly. Figure 1.6 depicts the database interactions in ADO.NET.
Three of these objects have been developed since Connections and Commands were introduced. The following sections describe these new objects: DataSet, DataReader, and DataAdapter.
DataSet
The following are major features of the DataSet object:
- DataSet is a stand-alone entity, which acts as a disconnected recordset that knows nothing about the source or destination of the data it contains. A DataSet contains entities such as tables, columns, relationships, constraints, and views.
- DataSet is a memory-resident representation of data that provides a consistent relational programming model independent of the data source.
- The DataSet has many XML characteristics, including the capability to produce and consume XML data and XML schemas. XML schemas can be used to describe schemas interchanged through Web services.
- A DataSet with a schema can actually be compiled for type safety and statement completion.
- The XML-based DataSet object provides a consistent programming model that works with all models of data storage including flat, relational, and hierarchical.
- The DataSet is independent of the source of its data; the managed provider has detailed and specific information. The managed provider connects, fills, and persists the DataSets across the datastores.
DataReader
The following are major features of the DataReader object:
- DataReader allows forward-only access over one or more of the resultsets obtained by executing a command and access to the column values within each row.
- Results are stored in the network buffer on the client after the execution of a query until you request them.
- DataReader increases application performance by retrieving data as soon as it is available instead of waiting for the entire results of the query to be returned.
- DataReader allows storage of only one row at a time in memory to reduce system overhead.
DataAdapter
The following are major features of the DataAdapter object:
- A DataAdapter is the object that connects to the database to fill the DataSet or DataReader and then connects back to the database to update the data, based on the operations performed while the DataSet held the data.
- DataAdapter represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.
- DataAdapter serves as a bridge between a DataSet and a data source for retrieving and saving data.
- DataAdapter has command object properties like InsertCommand, UpdateCommand, and DeleteCommand to update the data.
No comments:
Post a Comment