You are on page 1of 22

Chapter 1 Getting started with .NET Framework 4.

Chapter 1

Getting started with .NET Framework 4.0


.NET Framework is an essential component of the Windows operating system, which helps in
creating applications by integrating different programming languages, such as C#, Visual Basic,
J#, and Visual C++. This framework consists of a virtual execution system called the Common
Language Runtime (CLR) and a set of class libraries. CLR is a Microsoft product of the common
creating execution and development environments in which languages and libraries work
together.

Evolution of .NET:-
At the time of mid ninety, java was so popular to develop the application because of its platform
independent technique and open source policy of Sun Microsystems. Around 2002, Sun
Microsystems introduced the Java 2 Enterprise Edition (J2EE) to create the distributed
application, which means, the functioning of an application is distributed on several computers
based on the N – tier architecture. As the J2EE was gaining popularity, the market share of
Microsoft ultimately led to the turn down. Therefore, Microsoft starts working on a project
known as Next Generation Windows Services (NGWS) to recover the market share. The project
took around three years to build up, which is now known as .NET.
Microsoft released the different version of .Net with the different name as listed below:

Benefits of .NET Framework:

The following are the benefits of .NET Framework:

 Consistent Programming Model: Provides a consistent object-oriented programming


model across different language. You can use this model to create programs for
performing different tasks, such as connecting to and retrieving data from databases, and
reading and writing in files.

1
Chapter 1 Getting started with .NET Framework 4.0

Cross-Platform Support: Specifies that any windows platform that supports CLR can
execute .NET application, that is, .NET application enables interoperability between
multiple Windows operating systems.

Language Interoperability: Enables code written in different languages to interact with
each other. This allows reusability of code and improves the efficiency of the
development process.
Example: In an ASP.NET application created using Visual Basic language, you can
inherit a C# class in the application. The CLR has a built-in support for language
interoperability.

Automatic Management of Resource: Specifies that in .NET, you do not need to
manually free the application resources, such as files, memory, network, and database
connection. .NET Framework provides a feature called CLR that automatically tracks the
resource usage and helps you in performing the task of manual resource management.

Ease of Deployment: Specifies that the .NET Framework installs applications or
components that do not affect the existing applications. In most cases, to install an
application, you need to copy the application along with its components on the target
computer. In .NET, applications are deployed in the form of assemblies. Therefore,
registry entries are not required to store information about components and applications.
Therefore, the version problem is also eliminated in .NET Framework.

Architecture of .NET Framework 4.0:


The latest version of .NET provides a framework that helps in developing portable, scalable, and
robust applications. The applications developed in .NET Framework 4.0 can be executed in a
distributed environment. Therefore, you can say that the .NET Framework 4.0 is designed to
address the latest needs of the developers.
The architecture of .NET Framework 4.0 mainly consists of components of .NET Framework 2.0
and 3.0 with few enhancement as shown in below figure.

2
Chapter 1 Getting started with .NET Framework 4.0

Components of .NET Framework:

The .NET Framework provides the help to developers create new application. It provides all the
necessary components to develop and run .NET-based programs on your system. The
components of .NET Framework 4.0 architecture are as follows:
 Common Language Runtime (CLR)
 Common Type System (CTS)
 Metadata and Assemblies
 .NET Framework class library
 Windows Forms
 ASP.NET and ASP.NET AJAX
 ADO.NET
 Windows Workflow Foundation
 Windows Presentation Foundation
 Windows Communication Foundation
 Windows CardSpace
 LINQ
Let’s now discuss about each of them in detail.

Common Language Runtime (CLR):

CLR is an Execution Engine for .NET Framework application and is one of the most important
components of .NET Framework, provides a run-time environment to run the code and provides
various services to develop the application easily.
The services provided by CLR are –
 
 Memory Management Thread execution Code safety
 Exception Handling  Code execution  Verification
 Debugging  Language Integration  Compilation
 Security
Automatic Memory Management: CLR manage the allocation and de-allocation memory
automatically by using various built-in function. Therefore programmer need not write the code
to explicitly allocate and de-allocate memory to programs. This automatic memory management
resolves the issues of memory leaks and invalid memory references.

Garbage Collection: It is play an important role in CLR to prevent memory leaks during
execution of programs. The Garbage collection automatically releases the memory when it is not
being used.

Code Access Security (CAS): It is the CLR’s security system that enforce security policies by
preventing unauthorized access to protected resource and operations. CAS also helps in making

3
Chapter 1 Getting started with .NET Framework 4.0

the code robust, which implies that it makes the code robust, which implies that it makes the
code extensible and reusable.

Code Verifications: CLR imposes type safety and prevents the source code from performing
illegal operations, such as accessing invalid memory locations.

The following figure shows the process of compilation and execution of the code by the JIT
Compiler:

Fig 1.2: Compilation and Execution of the code


When you compile your source code by selecting .NET aware compilers such as Visual Basic,
C#, Visual C++, J#, or any of the third party compilers, such as COBOL, Perl or Eiffel. The
compiler converts source code in to IL / MSIL / CIL, which is CPU independent and the required
metadata is generated. The metadata contains the definition of types, member signature, the
members in the code, and other details that the code uses at the time of execution. After
compiling, the code is passed to the CLR at the runtime to a verification process that examines
the IL and metadata to check whether the code is safe, such as it should be able to access only
those memory locations which it is authorized to access. CLR uses the rules to examine the code
which are stated in the CLS and CTS. After verifying, a JIT [Just-In-Time] compiler extracts the
metadata from the file to translate that verified IL code into CPU-specific code or native code.
These type of IL Code is called as managed code.

The source code which is directly compiles to the machine code and runs on the machine where
it has been compiled such a code called as unmanaged code. It does not have any services of
CLR.

Let’s now explore the managed code, unmanaged code, and memory management in CLR.

4
Chapter 1 Getting started with .NET Framework 4.0

Managed Code: Managed code is the code that is executed directly by the CLR. The application
that are created using managed code automatically have CLR services, such as type checking,
security, and automatic garbage collection.
The process of executing a piece of managed code is as follows:
 Selecting a language compiler
 Compiling the code to IL[This intermediate language is called managed code]
 Compiling IL to native code
 Executing the code

Unmanaged Code: Unmanaged Code directly compiles to the machine code and runs on the
machine where it has been compiled. It does not have services, such as security or memory
management, which are provided by the runtime. If your code is not security-prone, it can be
directly interpreted by any user, which can prove harmful.

Memory Management: One of the most important services that the CLR provides during
managed execution is the automatic memory management. The CLR uses the garbage collector
to manage the allocation and release of memory for an application.

It is one of the advantages of CLR that is for the developers since it reduces the burden of
writing codes to manage memory while developing managed applications. Automatic memory
management removes common problems, such as forgetting to free an object which results in
memory leak, or attempting to access memory for an object that is already free.

CTS [Common Type Systems]:

The CTS defines the rules for declaring, using, and managing types at runtime. It is an integral
part of the runtime for supporting cross-language communication.

The common type system performs the following functions:

 Enables cross-language integration, type safety, and high-performance code


execution.
 Provides an object-oriented model for implementation of many programming languages.

Defines rules that every language must follow which runs under .NET framework like C#,
VB.NET, F# etc. can interact with each other.

The CTS can be classified into two data types, are


 Value Types
 Reference Types

The base class of all the types is the System.Object class. The hierarchy of the types as shown
below:

5
Chapter 1 Getting started with .NET Framework 4.0

Fig 1.3: hierarchy of value type and reference type

The following table shows some of the differences between values types and reference types.

Value Types Reference Types


Allocated on stack Allocated on heap
variable contains the address of memory location where
variable contains the data itself
data is actually stored
When we copy a value type variable to When copying a reference type variable to another
another one, the actual data is copied variable, only the memory address is copied. Both
and each variable can be independently variables will still point to the same memory location,
manipulated. which means, if we change one variable, the value will
be changed for the other variable too.
Integer, float, boolean, double etc are
string and object are reference types.
value types.
Derived from System.ValueType Derived from System.Object

CLS [Common Language Systems]:

The Common Language Specification (CLS) is a set of rules that a given .NET-aware compiler
must support to produce code that can be hosted by the CLR, while at the same time be accessed
in a uniform manner by all languages that target the .NET platform. In many ways, the CLS can
be viewed as a subset of the full functionality defined by the CTS.

The CLS helps enhance and ensure language interoperability by defining a set of features that
developers can rely on to be available in a wide variety of languages. The classes that follow the
rules specified by CLS are termed as CLS-complaint classes. The classes defined in the .NET
Framework class library are CLS-Compliant. The CLS describes a set of features that different
languages have in common. CLS Compliance is especially important when creating software
components that will be used by other languages.

6
Chapter 1 Getting started with .NET Framework 4.0

The most important rules, and which apply to public and protected members are
i. All types appearing in a method prototype must be CLS-compliant
ii. Array elements must have a CLS-compliant element type. Arrays must also be 0-indexed
iii. A CLS compliant class must inherit from a CLS-compliant class only

Metadata and Assemblies:

A metadata is binary information that describes your program, stored in a CLR Portable
Executable (PE) file or the memory.

The metadata contains the following:



Assembly information, which includes the metadata identity that can be name, version,
culture, public key, the types of assemblies, other reference assemblies, and security
permissions.

Information about types, such as name, visibility, base class, interfaces used, and members
(methods, fields, properties, events, and nested types)

Attribute information that modifies the types and members of a class.

An assembly contains a self-describing binary file that can be either Dynamic Link Library
(DLL) or Executable (EXE). It also contains a collection of types, such as classes, interfaces and
structures.

There are two types of assembly:

i. Single file assembly: Single assembly can contain multiple code files of single code file
can have more than one assembly. It contains the type information and implementation as
well as the assembly’s manifest into a single physical file.

Example: Class Libraries, Windows Forms / WPF applications, Console applications and
Windows Services

Fig 1.4: Structure of Single-File Assembly

7
Chapter 1 Getting started with .NET Framework 4.0

Multi-file assembly:
An assembly can consist of one or more files called modules. Exactly one of these modules
contains the assembly manifest.
Note that the files in a multi-file assembly can reside in separate locations and are linked together
with the assembly manifest. Multi-file assemblies are rare, and Visual Studio doesn’t directly
support their creation. The most common reason for multi-file assemblies is when a single
assembly combines code from multiple programming languages.

Fig 1.5: Structure for Multi-file Assembly

Assemblies can be two types:

Static assemblies: Static assemblies include interfaces, classes and resources. These assemblies
are stored in PE (Portable executable) files on a disk.

Dynamic assemblies: Dynamic assemblies run directly from the memory without being saved to
disk before execution. However, after execution you can save the dynamic assemblies on the
disk.

Assembly Content:

Assembly is a logical unit that consists of 4 elements as follows:

 Manifest
 Metadata
 IL code(static or dynamic)
 Set of resources[bitmaps, jpeg]

8
Chapter 1 Getting started with .NET Framework 4.0

Assembly manifest: Assembly contains data that describes how elements are related to each
other within the assembly. The manifest, also known as assembly manifest, contains the
assembly metadata needed for providing the assembly’s version requirements and security
identity. The manifest can be stored either in a PE file with IL code or in a standalone PE file
that contains only the manifest information. The list of information listed below

Table1.1: Information stored in the assembly manifest


Information Description
Assembly name Specifies the name of the assembly
Indicates a major version number, a minor version number, and a revision
Version number and build number. The CLR uses these numbers to enforce the version
policy.
Provides information about the culture or language that the assembly
Culture
supports.
Strong name Indicates a public key from the publisher if the assembly contains a
information strong name
List of all files in Contains an alphanumeric string that is generate as per the contents of a
the assembly file (hash) of each file contained in the assembly and a file name.
Contains the information required to map a type reference to the file that
Type reference contains its declaration and implementation. Types exported from the
information
assembly use the type reference information.
Provides the list of assemblies, which are used as a reference by the
Information on assembly. The reference of assembly contains the whole details of
referenced
dependent assembly, such as name, assembly metadata and public key, if
assemblies
the assembly is strong named.

Global Assembly Cache:

The Global Assembly Cache (GAC) is a folder in Windows directory to store the .NET
assemblies that are specifically designated to be shared by all applications executed on a system.
One thing to remember is that the assemblies must be sharable by registering them in the GAC,
only when needed; otherwise, they must be kept private. Each assembly is accessed globally
without any conflict by identifying its name, version, architecture, culture and public key.
Further, it is not mandatory to install the assemblies in the GAC to make them accessible to the
COM interop or unmanaged code, where COM interop is a service that enables .NET Framework
objects to communicate with COM objects.
You can deploy an assembly in GAC by using any one of the following:
 An installer that is designed to work with the GAC
 The GAC tool known as Gacutil.exe
 The Windows Explorer to drag assemblies into the cache.

9
Chapter 1 Getting started with .NET Framework 4.0

Strong Name Assembly:

A Strong Name contains the assembly’s identity, that is, the information about the assembly’s
name, version number, architecture, culture and public key.
 Using Microsoft Visual Studio .NET and other tools, you can provide a strong name
to an assembly.
 By providing strong names to the assembly, you can ensure that assembly is globally
unique.

Benefits:

Provides uniqueness to the names by generating a private key.

Ensures that a version of the assembly you are using comes from the same publisher that
created the version the application was built with

Facilitates integrity check, which ensures that the contents of the assembly do not change since its
last build.

Private and Shared Assembly:

A single application uses an assembly, then it is called as a private assembly.

Example: If you have created a DLL assembly containing information about your business logic,
then the DLL can be used by your client application only. Therefore, to run the application, the
DLL must be included in the same folder in which the client application has been installed. This
makes the assembly private to your application.

Assemblies that are placed in the Global Assembly cache so that they can be used by multiple
applications, then it is called as a shared assembly.

Example: Suppose the DLL needs to be reused in different applications. In this scenario, instead
of downloading a copy of the DLL to each and every client application, the DLL can be placed
in the global assembly cache by using the Gacutil.exe tool, from where the application can be
accessed by any client application.

Side-by-Side Execution Assembly:

The process of executing multiple versions of an application or an assembly is known as side-


by-side execution. Support for side-by-side storage and execution of different versions of the
same assembly is an integral part of creating a strong name for an assembly.
 Strong naming of .NET assembly is used to provide unique assembly identity by
using the sn.exe command utility.
 The strong-named assembly’s version number is a part of its identity, the runtime can
store multiple versions of the same assembly in the GAC.
 Load these assemblies at runtime.
10
Chapter 1 Getting started with .NET Framework 4.0

.NET Framework Class Library:

The .NET Framework includes classes, interfaces, and value types that helps in speeding up the
application development process and provide access to system functionality. To facilitate
interoperability between languages, most .NET Framework types are CLS-compliant and can be
used from any programming language whose compiler conforms to the common language
specification (CLS).

The .NET Framework types are the foundation on which .NET applications, components, and
controls are built. These entities perform the following functions:
 Represent base data types and exceptions
 Encapsulate data structures
 Perform I/O
 Access information about loaded types
 Invoke .NET Framework security checks
 Provide data access, rich client-side GUI, and server-controlled, client-side GUI

The .NET Framework Class Library (FCL) is a library consisting of namespaces, classes,
interfaces, and data types included in the .NET Framework. This library is organized into
namespaces that contain functionally related groups of classes. These namespaces are divided
among different categories, such as data access, common types, debugging, file access, network
communication, security, Windows applications, Web applications, Web services, XML data etc.
The following points need to be remembered while using the FCL:
 The classes, interfaces, structures, and enumerated values are collectively referred to as
types.
 The different types in the framework are arranged in a hierarchy of namespaces.
Namespaces are arranged a hierarchy that has words separated by Dots (.).
Example: System.IO.Stream, System.Windows.Forms.Form respectively
 The System namespace is a parent of all the types available in the .NET Framework
Class Library.
Example: System namespace contains base data type’s classes, such as Object, Int,
Array, and Short.
 All types must have a base class. The exception to this rule is the System.Object type,
which acts as the base type for all types in .NET Framework. This implies the compiler
explicitly declares its base class to the Object class.

Windows Forms (WF):


Windows forms is the graphical representation of any window displayed in an application. It is
included as a part of Microsoft’s .NET Framework. You can create an application using Window
Forms in any CLR supported language. A Windows Form is used to either accept input from or

11
Chapter 1 Getting started with .NET Framework 4.0

display information to the user. In Windows Forms, you add controls to the forms and raise
events, such as mouse-click, which is handled by event handlers in an application.

ASP.NET and ASP.NET AJAX:

ASP.NET is a web development mode, which is used to deliver interactive and data-driven web
application over the internet. It also consists of a large number of controls, such as text boxes,
buttons, and labels for assembling, configuring, and manipulating code to create Hyper Text
Markup Language (HTML).

Advantages of ASP.NET:

 Better Performance: Specifies that when you request a web page for the first time after
compiling ASP.NET code, the CLR compiles the code and stores the cached copy of the
result. Now, for any subsequent calls to the same page, the cached copy of the result is
retrieved instead of going back to the server.

 Improved Security: Refers to the different methods of authentication included in


ASP.NET:

Forms: Allows the ASP.NET application to use its own custom business logic for
authentication.

Windows: Checks the identity of a user against the Windows user accounts that
are stored on the Web Server. If the credentials of a user match with that of a
Windows user account, then the user is authenticated.

 Greater Scalability: Specifies that the session states in ASP.NET are maintained in a
separate process on a different machine or database. This enables cross-server sessions to
occur, solving the problem of web forms when more web servers need to be added as the
traffic grows.

 Cookie-less Sessions: Specifies that ASP.NET stores the session even when the cookies in a
Web browser are disabled. In such a case, the session ID is passed as a part of the Uniforms
Resource Locator (URL).

AJAX, which is also known as Atlas, is used as an extension for ASP.NET to develop and
implement the AJAX functionality. ASP.NET AJAX has both side client and server
components to develop the Web applications, which can update the information on a Web
application without reloading the page completely.

Advantages of using AJAX:

 Asynchronous: Enables asynchronous calls to the Web server without making the users
wait for the data.

12
Chapter 1 Getting started with .NET Framework 4.0

 Minimal transfer of data: Helps in sending only a part of the modified data to the web
server to minimize the network traffic and perform the operations quicker.

 Minimal processing on the Web server: Minimizes the processing on the Web server as
only the necessary data needs to be sent. Now, the server is not required to send a full page
back to the user.

 Context: Reduces burden on the server by sending a request back to the server through the
client-side script. AJAX-based applications implement partial page post backs instead of full
page post backs, which reduce the data traffic between the client and server.

ADO.NET:

ADO.NET is a technology used for working with data and databases of all types. It provides
access to data sources, such as Microsoft SQL Server, data sources exposed through OLE DB,
and Extensible Markup Language (XML).You can use ADO.NET too connect to data sources
for retrieving, manipulating, and updating data.

Advantages:

 Disconnected Data Architecture: Implies that applications connect to the database only
when data needs to be retrieved or modified. After the database operation has been
performed, the connection to the database is closed. To perform any database operation
again, the connection with the database will have to be re-established.

 Cached Data in Datasets: Follows a disconnected architecture for accessing or modifying


data. It is not required for the applications to connect to the database for processing each
record. Therefore, the data is accessed and later stored in the datasets. A dataset is a cached
set of database records, which is independent of data source. Even when you are
disconnected from the database on which you are working, you can make modifications in
the database.

 Scalability: Reduces the traffic on the database and saves the resources to make the
database more efficient in meeting the demands of the user. ADO.NET help in attaining
scalability while working with datasets. All database operations are performed on the dataset
instead of on the database.

 Transfer of Data in XML Format: Transfers data from a database into a dataset and from
the dataset to another components using XML, which is the standard format used for
transferring data in ADO.NET. You can also use an XML file as a data source and store the
data from it into a dataset. One need not know XML since data conversion from and to XML
is abstracted from the user.

13
Chapter 1 Getting started with .NET Framework 4.0

 Interaction with the Database through Data Commands: Specifies that database
operations are performed by executing the data commands. All operations on database, such
as retrieving, modifying, or updating of data are performed using data commands. A data
command is either a Structured Query Language (SQL) statement or a stored procedure.

Windows Workflow Foundation

WF is a technology introduced by Microsoft, which provides a programming model for building


workflow based applications on Windows. It includes activities, workflow runtime, workflow
designer, and a rules engine. WF is a part of .NET Framework 3.0, 3.5 and 4.0.

Feature
 Activities: Receives some parameters from the developer, execute the actions specified in
the parameters, and then the flow is transferred to the next activity.
Example: The code for ifelse activities.
 Workflow Designer: Designs workflows by placing activities within the workflow model.
One interesting feature is that it can be re-hosted within any Windows Forms application.
 Workflow Runtime: Executes the activities in a workflow. It is a lightweight and extensible
engine that resides within a .NET process, facilitating the developers to bring workflow to
anything from a Windows Forms application to an ASP.NET website or a Windows Service.
 Rules Engine: Enables declarative, rule-based development for workflows and any .NET
application to be used.
The architecture of WF is shown below:

MODEL LAYER
Activities:
Adding Built-in activities Building rules and workflows
Adding Custom activities

RUNTIME LAYER

Executing rules, tracking and scheduling

Managing state lifecycle and activation

HOSTING LAYER
Provides Runtime Services such as:
 Communication, Persistence, Tracking, Timer, Transactions, Threading
 Enables adding custom services

Fig 1.6: Windows Workflow Foundation Architecture

14
Chapter 1 Getting started with .NET Framework 4.0

There are 3 layers:


 Model Layer: The top layer is model layer where the developers build their code to run in
the workflow. This layer provides the developer to following activities:
 Add built-in activities
 Create Custom activities
 Building rules and workflows

 Runtime Layer: The second layer is runtime layer. It ensures that the processes, such as
execution of rules, tracking and scheduling and managing state lifecycle and activation, take
place.

 Hosting Layer: The last layer is hosting layer, which connects the engine and the process
that is being executed. It also provides a set of services, such as persistence, timer, tracking,
communication, transactions, and threading, required for managing and controlling the
workflow. WF also contains built-in services that provide the interfaces required to work
with .NET Framework 2.0 and its advanced versions.

Windows Presentation Foundation (WPF):


WPF provides the base for building applications and a clear separation between the user interface
and the business logic. WPF helps in building interfaces that include documents, media, two or
three dimensional graphics, animations and web-like characteristics. The architecture of WPF
shown below:

Fig 1.7: Architecture of WPF

15
Chapter 1 Getting started with .NET Framework 4.0

WPF provides document services, such as XML Paper Specification (XPS) documents and
packaging services.
 XPS documents are shown with an XML-based schema that defines the layout and visual
appearance of a page.
 The WPF namespace System.IO.Packaging helps in organizing data, content, and
resources of your application into a single, portable, easy to access, and distributable .zip
document.
WPF aims at unifying several user interface services, such as application services, controls
layout, data-binding and deployment services. It provides shape for 2-D graphics by providing
in-built brushes, pens, and geometries.
WPF supports various video formats, such as Windows Media video (WMV), Moving Picture
Experts Group (MPEG), and some Audio Video Interleave (AVI) files. It also supports audio
files, some common image formats and animations.
WPF provides some basic services, such as accepting input and raising events, property system,
and accessibility.

Windows Communication Foundation:

WCF is one of the new technologies introduced by Microsoft in .NET Framework 3.0 for
building and running connected systems. It is a service-oriented technology for developing
applications in a distributed system that provides services to the client applications. WCF is
simply an enhanced technology for providing the same functions in a better way.
The enhancements of WCF as compared to the previous technologies are as follows:
 Merges technologies, such as Web services, remoting, distributed transactions, and
message queuing in one place and reduces development time.
 Consists of many powerful enterprise features
 Integrates easily with other technologies and consequently, enables greater
interoperability.

The WCF Architecture is composed of the following five layers:

 Application: Represents the location of the application.

 Contracts: Consists of services, data and message contracts as well as bindings and
policies. The contracts layer gives you information about the different features of the
message system [which involves sending and receiving the messages from one end to
another].

 Service Runtime: Gives information about the different behaviours that take place at
runtime. This layers loads all the services.
16
Chapter 1 Getting started with .NET Framework 4.0

 Messaging: Gives information about different channels that are required at the time of
processing a message. This layer deals with the message content that needs to be
communicated.

Fig 1.8: Architecture of WCF

 Activation and Hosting: This layer deals any service can be hosted using the Internet
Information Services (IIS) or Windows Activation Service.

The WCF programming model combines Web Services, .NET remoting, distributed transactions,
and message queues into a single service-oriented programming model for distributed
computing.

Windows CardSpace:

Windows CardSpace is a client software provided by Microsoft that improves the safety of
accessing resources and helps in sharing personal information on the internet. It helps
programmers in developing websites and software that are less prone to identity-related attacks,
such as phishing.

17
Chapter 1 Getting started with .NET Framework 4.0

Advantages:

 Reducing the problems of traditional online security mechanisms by relying on separate


desktop and cryptographically strong authentication rather than on user names and
passwords.

 It facilitates secure online transactions, such as online shopping, banking, and bill
payment.

You can create a card using the WCS utility that comes with .NET 4.0 as shown below Windows
CardSpace user interface:

Fig 1.9: WCS User Interface

WCS is based on the identity meta system. This system allows you to use different digital
identities across different platforms. There are two types of cards available:

Personal Cards: Refers to the card that is based on the self-issued identity providers

Managed Cards: Refers to the card that is based on identity providers provided by vendors
other than Microsoft.

Suppose a CardSpace enabled site wants to retrieve the personal information of the user
(identifies) and for that demands a particular type of card. The CardSpace then stored identifies
as virtual information card. The user selects the card to use the CardSpace software contacts the
identity provider to get the digitally signed token that contains the required information. WCS is
built with an open set of XML-based protocols, which includes WS-Security, XS-

18
Chapter 1 Getting started with .NET Framework 4.0

MetadataExchange, and WS-SecurityPolicy. With these set of protocols, any technology or


platform can integrate with the CardSpace.

The overall process of CardSpace contains issuing, acquiring and using digital identifies that can
be defined by the following three distinct roles:
 User – refers to an entity containing a digital identity.
 Identity Provider – refers to a provider that provides a digital identity to the user. The
digital identity is used to provide information about the username and password of the
user. Digital identifies created by the identity providers may contain different information
and provide different levels of assurance to identify the actual user.
 Relying Party – refers to an application that relies on a digital identity. It can use an
identity to authenticate a user and then make authorization decision, such as allowing or
disallowing the user to access information.

LINQ:

LINQ is an acronym for Language Integrated Query, which is one of the components of .NET
Framework 4.0 that adds native data querying capabilities to .NET languages by using syntax
similar to SQL.
The following are simple LINQ query in different language:

Visual Basic

Dim query = From s In Students Where s.Gender = “M”


Select s.Name

C#
var query = from s in Student where s.Gender =
“M”; select s.Name;

When you execute the preceding query, it returns the names of all the male students and is stored
in the variable query.
To print that list, you have to write the following lines of code:

Visual Basic C#
For Each name In query foreach(var name in query)
Response. Write(name) {
Next Response.Write(name);
}

19
Chapter 1 Getting started with .NET Framework 4.0

In the preceding code, you can find that the syntax of the query is similar to the SQL, which we
normally follow for accessing relational data. It is important to note that even if it looks similar
to SQL, the LINQ query displayed is not an SQL statement. Instead, it is purely in C# language.

LINQ queries resemble SQL, they are not restricted to accessing only relational databases. LINQ
enabled data access components are as follows:

 LINQ to ADO.NET:- Includes two options, LINQ to SQL, which translates a query into
an SQL query, and then issues it against the tables specified in the query in an SQL
Server database, and LINQ to DataSet, which executes a query on the contents of a
DataSet.

 LINQ to Object:- Allows querying objects in a collection. LINQ to Objects is not


dynamic. After creating and using the result set, any changes made to the source
collection do not automatically update the result set.

 LINQ to XML:- Allows querying of XML data. In addition, it helps in creating and
manipulating XML data. This option has a different syntax; however, the basic LINQ
query remains the same.

Exploring New Features of .NET Framework 4.0:

.NET Framework 4.0 helps in providing a consistent object-oriented programming environment.


It helps the developers to experience consistent programming environment. There are many new
features introduced that listed below.

 Improvements in the application compatibility and deployment support


 Dynamic Language Runtime(DLR)
 Managed extensibility Framework
 Parallel computing
 Improved security model
 Networking improvements
 Improved core ASP.NET services
 Improvements in WPF
 Improved entity framework
 Integration of WCF and WF

20
Chapter 1 Getting started with .NET Framework 4.0

Improvements in the application Compatibility and Deployment support:

The applications that are developed in the earlier versions of .NET Framework are supported in
this version. This implies that the new version of .NET Framework is compatible with the
applications that are developed using the earlier version of .NET Framework.

.NET Framework 4.0 does not check the version of CLR automatically to run an application
developed in an earlier version of .NET Framework. You can run an application created in the
older version of .NET Framework by specifying the supported runtime in the application
configuration file by using the <supportedRuntime> element.

.NET Framework 4.0 also has an improved deployment support as two new features have been
introduced in this version.

 .NET Framework Client Profile – Improves the deployment process by providing a fast
deployment of Windows Forms, Console, or WPF applications.

 In-Process Side-by-Side Execution – Helps in loading and starting multiple versions of


.NET Framework. This implies that you can run multiple versions of CLR in a single
process.

Dynamic Language Runtime (DLR):


DLR feature is introduced in .NET Framework 4.0 to implement dynamic languages, such as
Python and Ruby, on the .NET Framework. This implies that the DLR is a runtime environment
that adds services to the CLR, to implement dynamic languages. The namespace of DLR is
System.Dynamic.
Advantages:

Implements dynamic features in the statically typed languages, such as C# and Visual
Basic(VB), so that these languages can also create dynamic objects

Enables interoperation between statically typed languages and dynamic languages, so that the
objects that are implemented in one language can easily be used by other languages.

Helps the developers to concentrate on the specific language feature as the developers do not
have to create code generators.
The architecture of DLR shown below and it adds the following set of services to CLR for the
better support of dynamic languages:
 Expression trees – Allows you to define variable assignments and function loops

21
Chapter 1 Getting started with .NET Framework 4.0

Fig1.9: Displaying the DLR Architecture

 Call site caching – allows DLR to store information about method calls so that in case of
any subsequent calls to the method, the DLR can use the cache history information.
 Dynamic object interoperability – Refers to the set of classes that can be used to create
dynamic objects.
The binder helps DLR to communicate with not only the .NET Framework but also with other
infrastructure and services, such as Silverlight and Microsoft Office.
Advantage of binder: is to inform the DLR about the language and how to perform operations in
a call site by using expression trees.

22

You might also like