Unit 1
Introduction to .NET Framework
The .NET Framework is a software framework developed by Microsoft for building
and running applications on Windows operating systems. It provides a
comprehensive set of tools, libraries, and languages for developing various types of
applications, including web applications, desktop applications, and services.
.NET technology was introduced by Microsoft, to catch the market from the SUN's
Java. Few years back, Microsoft had only VC++ and VB to compete with Java, but Java
was catching the market very fast. With the world depending more and more on the
Internet/Web and java related tools becoming the best choice for the web
applications, Microsoft seemed to be loosing the battle. Thousands of programmers
moved to java from VC++ and VB. To recover the market, Microsoft announced .NET.
.NET framework comes with a single class library. And thats all programmers need to
learn!! Whether they write the code in C# or VB.NET or J#, it doesn't matter, you just
use the .NET class library. There is no classes specific to any language. There is
nothing more you can do in a language, which you can't do in any other .NET
language. You can write code in C# or VB.NET with the same number of lines of code,
same performance and same efficiency, because everyone uses same .NET class
library
Evolution of .NET Technology
There are three significant phases of the development of .NET technology.
1. OLE Technology
2. COM Technology
3. .NET Technology
OLE Technology(Object Linking and Embedding)
– Easy interprocess communication – Embed documents from one application into
another application
– To enable one application to manipulate objects located in another application –
Ex: inter operability between various products such as MS word and MSExcel
COM Technology( Component Object Model)
– Monolithic approach leads to many problem of maintainability and testing
– A program is broken into number of independent components where each one
offers a particular service
– Each component can be developed and tested independently and then integrated
into main system.
– Benefits: – Reduces the overall complexity of software.
– Enables distributed development across multiple organization or departments.
– Enhances software maintainability
.net Technology
– Third generatiom component model
– IPC in COM is replaced by Intermediate Language(IL or MSIL)
– Interoperability by compiling code into IL. – Metadata
.NET Programming Languages:
 C# .NET: A modern, object-oriented language used for a wide range of application
   types.
 VB.NET: A language designed for ease of use, with syntax similar to traditional
   Basic.
 F# .NET: A functional-first programming language, well-suited for complex
   algorithms and data processing.
 C++ .NET: An extension of C++ designed for managed code applications.
 J# .NET: A language that provides .NET compatibility for Java developers.
 IronRuby, IronPython: .NET implementations of the Ruby and Python languages.
 Other Languages: JScript.NET, C Omega, ASML, and more.
Features of .NET
 It is a platform neutral framework.
 It is a layer between the operating system and the programming language.
 It supports many programming languages, including VB.NET, C# etc.
  .NET provides a common set of class libraries, which can be accessed from any
.NET based programming language. There will not be separate set of classes and
libraries for each language. If you know any one .NET language, you can write code in
any .NET language.
  In future versions of Windows, .NET will be freely distributed as part of operating
system and users will never have to install .NET separately
.Net Framework Architecture
The architecture of the .Net framework focuses on two main things: The first of
these is that the framework code is largely independent of the language in which it is
written. For example, a framework written in C# can contain calls to libraries written
in C++, as well as to libraries written in other programming languages. This allows
.Net programs to be ported to a wide variety of platforms. The second main goal of
the .Net framework is that it should be easy to adopt.
The framework should also be designed in a way that makes it easy to port the
program to a different platform or make the program run on a different type of
computer.
It has also been built in a way that makes it easy to extend the program with new
features.
Components of the .NET Framework
  1. Common Language Runtime (CLR)
  2. .NET Framework Class Library (FCL)
  3. The Base Class Library(BCL)
  4. Common Type System (CTS)
5. Common Intermediate Language(CIL)
6. Common Language Specification (CLS)
Common Language Runtime (CLR) :
  The CLR is the heart of .NET framework. It is .NET equivalent of Java Virtual
  Machine (JVM). It is the runtime that converts a MSIL (Micro Soft Intermediate
  Language) code into the host machine language code, which is then executed
  appropriately. The CLR provides a number of services that include:
   Loading and execution of codes
   Memory isolation for application
   Verification of type safety
   Compilation of IL into native executable code
   Providing metadata
   Automatic garbage collection
   Enforcement of Security 5
   Interoperability with other systems
   Managing exceptions and errors
   Provide support for debugging and profiling
Common Type System (CTS) :
  The language interoperability, and .NET Class Framework, are not possible
  without all the language sharing the same data types. What this means is that
  an ―int‖ should mean the same in VB, VC++, C# and all other .NET compliant
  languages. Same idea follows for all the other data types. This is achieved
  through introduction of Common Type System (CTS). CTS, much like Java,
  defines every data type as a Class. Every .NET compliant language must stick
  to this definition. Since CTS defines every data type as a class; this means that
  only ObjectOriented (or Object-Based) languages can achieve .NET
  compliance.
.Net Framework Class Library(FCL):
The FCL is part of the Common Language Runtime. It is loaded when the program
starts and unloaded when the program ends. Through this loading and unloading
process, the CLR is able to locate and load the FCL into memory when it is required.
The Framework Class Library (FCL) is an essential part of the .NET Framework,
providing a comprehensive set of reusable classes, interfaces, and value types that
developers use to build applications.
It serves as the foundation for all .NET applications by offering core functionalities
such as file input/output, database connectivity, string manipulation, collections,
networking, security, and user interface development.
These features are organized into a hierarchical structure of namespaces, such as
System, System.IO, System.Net, and System.Data.
The FCL is designed to work seamlessly across all .NET-supported programming
languages like C#, VB.NET, and F#, ensuring consistency and interoperability. While
often used interchangeably with the Base Class Library (BCL), it's important to note
that BCL is actually a subset of FCL, containing only the most fundamental classes.
The FCL extends these capabilities further, including advanced components like
ADO.NET, ASP.NET, and Windows Forms, making it a powerful and versatile toolkit
for .NET development.
The Base Class Library(BCL):
In the .NET Framework, the Base Class Library (BCL) is a foundational set of classes
and types that provide fundamental functionality for application development. It
serves as the bedrock upon which many .NET applications are built, offering reusable
components for common tasks like string manipulation, I/O, collections, and
threading. The BCL is a subset of the larger Framework Class Library (FCL).
Common Intermediate Language(CIL):
In the .NET Framework, CIL (Common Intermediate Language) is the platform-
independent bytecode that .NET applications are compiled to before execution. This
intermediate language is then converted into machine code by the CLR (Common
Language Runtime). Think of CIL as a bridge between the source code and the final
executable, allowing .NET applications to be run on different systems without
recompilation.
When you write a program in a .NET language like C#, F#, or VB.NET, the
compiler doesn't directly convert it into machine code. Instead, it compiles the
code into a low-level, platform-independent set of instructions called CIL. This
CIL is stored in an assembly file.
Common Language Specification (CLS):
CLS (Common Language Specification) is a part of CLR in the .NET Framework.
The .NET Framework supports many programming languages such as C#,
VB.NET, J#, F#, etc. Every programming language has its own syntactical rules for
writing the code which is known as a language specification. One programming
language’s syntactical rules (language specification) cannot be understood by
other programming languages. But, there can be situations where we need to
communicate between two different programming languages. In order to ensure
smooth communication between different .NET Supported Programming
Languages, the most important thing is that they should have Common
Language Specifications which ensures that language specifications defined in
two different languages get compiled into a Common Language Specification .
CLR in .NET Framework will execute all programming language’s code. This is
possible because CLR has its own language specification (syntactical rules) which
are common to all .NET Supported Programming Languages. At the time of
compilation, every language compiler should follow this language specification
of CLR and generate the MSIL code. This language specification of CLR is
common for all programming languages and this is known as Common Language
Specifications (CLS).
Just-in time Compilation:
Just-In-Time compiler(JIT) is a part of Common Language Runtime
(CLR) in .NET which is responsible for managing the execution of .NET programs
regardless of any .NET programming language. A language-specific compiler
converts the source code to the intermediate language. This intermediate
language is then converted into the machine code by the Just-In-Time (JIT)
compiler. This machine code is specific to the computer environment that the JIT
compiler runs on.
The JIT compiler converts the Microsoft Intermediate Language (MSIL) or
Common Intermediate Language(CIL) into the machine code. This is done before
the MSIL or CIL can be executed. The MSIL is converted into machine code on a
requirement basis i.e. the JIT compiler compiles the MSIL or CIL as required
rather than the whole of it. The compiled MSIL or CIL is stored so that it is
available for subsequent calls if required.
Garbage Collection:
Garbage collection is a memory management technique used in the .NET
Framework and many other programming languages. In C#, the garbage
collector is responsible for managing memory and automatically freeing up
memory that the application is no longer using.
The garbage collector periodically scans the application's memory to determine
which objects are still being used and which are no longer needed. Objects that
are no longer being used are marked for garbage collection, and their memory is
freed up automatically by the garbage collector.
1. Allocate memory: When objects are created, the garbage collector allocates
   memory from the managed heap.
2. Identify unused objects: The garbage collector periodically identifies objects
   that are no longer referenced by the application.
3. Reclaim memory: The garbage collector reclaims memory occupied by
   unreferenced objects, making it available for future allocations.
Web services:
A web service is an XML-based information exchange system that creates direct
interaction between the two applications over the internet or network in order
to exchange data or information. It enables us to communicate and exchange
data or information between two different applications created in the same or
different languages over the internet or network. For example, if we use
multiple software systems and we need to transfer data from one application to
another application then a web service is the best source to accomplish this
task. The software system that sends requests for data is called a service
requester whereas the software system that processes the request and provides
the data is called a service provider. A web service works between all types of
applications software and it does not matter if both the service requester
software and service provider software are written in different programming
languages because web services use XML files for data exchange and most
software applications, however, interpret XML tags
Functions of Web Services
 It's possible to access it via the internet or intranet networks.
 XML messaging protocol that is standardized.
 Operating system or programming language independent.
 Using the XML standard, it is self-describing.
 A simple location approach can be used to locate it.
Components of Web Service
XML and HTTP is the most fundamental web services platform. The following
components are used by all typical web services:
SOAP (Simple Object Access Protocol)
SOAP stands for "Simple Object Access Protocol." It is a transport-independent
messaging protocol. SOAP is built on sending XML data in the form of SOAP
Messages. A document known as an XML document is attached to each
message. Only the structure of the XML document, not the content, follows a
pattern. The best thing about Web services and SOAP is that everything is sent
through HTTP, the standard web protocol.
A root element known as the element is required in every SOAP document. In an
XML document, the root element is the first element. The "envelope" is
separated into two halves. The header comes first, followed by the body. The
routing data, or information that directs the XML document to which client it
should be sent to, is contained in the header. The real message will be in the
body.
UDDI (Universal Description, Discovery, and Integration)
UDDI is a standard for specifying, publishing and discovering a service provider's
online services. It provides a specification that aids in the hosting of data via
web services. UDDI provides a repository where WSDL files can be hosted so
that a client application can discover a WSDL file to learn about the various
actions that a web service offers. As a result, the client application will have full
access to the UDDI, which serves as a database for all WSDL files.
The UDDI registry will hold the required information for the online service, just
like a telephone directory has the name, address, and phone number of a
certain individual. So that a client application may figure out where it is.
WSDL (Web Services Description Language)
If a web service can't be found, it can't be used. The client invoking the web
service should be aware of the location of the web service. Second, the client
application must understand what the web service does in order to invoke the
correct web service. The WSDL, or Web services description language, is used to
accomplish this. The WSDL file is another XML-based file that explains what the
web service does to the client application. The client application will be able to
understand where the web service is located and how to use it by using the
WSDL document.
Unified classes:
The Unified Classes (Base Class Library) is a set of classes that provide useful
functionality to CLR programmers. The .NET Framework class library exposes
features of the runtime and simplifies the development of .NET-based
applications. In addition, developers can extend classes by creating their own
libraries of classes. All applications (Web, Windows, and XML Web services)
access the same .NET Framework class libraries, which are held in namespaces.
All     .NET-based     languages      also   access   the    same     libraries.
The run time is responsible for managing your code and providing services to it
while it executes, playing a role similar to that of the Visual Basic 6.0 run time.
NET provides a unified class library, called the Base Class Library (BCL), which
includes thousands of built-in classes that offer consistent functionality across
different application types.
These include classes for:
      File I/O (System.IO)
      Collections (System.Collections)
      Networking (System.Net)
      Threading (System.Threading)
      Data Access (System.Data)