Training File 2013 by Numeric Infosystems Gwalior
Training File 2013 by Numeric Infosystems Gwalior
We have entered the age of digital technology. Computer exists everywhere from a small
kiosk to giant corporate house. Amongst all the sectors, information technology is following
and will pave a path for faster growth. In fact e-business is becoming the most favored
word with corporate as it took over from traditional business practices.
A clear perception of the growing requirement of the corporate world in the area of IT has
enabled Numeric Info System Pvt Ltd. to develop programs of specific relevance for the
present and the future.
Numeric Info System Pvt Ltd. is a leading solution provider for Internet based applications.
Established in 1996, The Company has been promoted by some highly experienced
Professionals dedicated to provide total IT solutions under one roof. It possesses not only
the latest technology gadgets but also the most knowledgeable and experience hands to
offer most user friendly customized solutions.
Numeric Info System Pvt Ltd. provides high quality on site services for software
development and the end users on a broad range of hardware & software platforms and
latest technologies.
Within the first year of its operations, Numeric Info System Pvt Ltd. has carved a niche for
itself in the IT industry and has increased its business by acquiring some major domestic
projects. No doubt the company has been able to make a name for itself in a relatively short
span of time only because of its ability and commitments to ensure customer satisfaction by
rewarding quality work on right time and in a right manner.
At Numeric Info System Pvt Ltd. with Technical proficiency and expertise, we cohesively
integrate graphic design with web page layout, with interactive programming, with database
driven content, to plan, build and deploy e- business and to emerge as one of the top IT
service provider.
The business philosophy of the company is to lay emphasis on Human Values and Personal
Relations. 'At Numeric Info System Pvt Ltd- Technology meets emotions and limits
are higher than the sky.' Great stress is laid on proper communication, transparency and
human relations, which forms an integral part of the corporate culture. At Numeric Info
System Pvt Ltd, we not only develop products but we develop relationships.
We at Numeric Info Systems Pvt Ltd. believe in teamwork. With every new day the quest for
acquiring new competencies continues. Forever searching, experimenting, innovating,
learning, moving ahead with our sincere efforts and dedication, shaping the future, and
challenging our competencies to create new opportunities, is a never-ending process in the
company.
SERVICES
Numeric Info System Pvt Ltd .takes you to the next dimension of Web performance. The
focus: Meaningful solutions that foster measurable results.
Numeric Info Systems Pvt Ltd. always strives to provide customer satisfaction through its
legendary services at an affordable price. We believe in long term relationship with our
customers and to add more and more to our client list from the reference of our existing
once.
Software Development
Client/Server Applications
Distributed Applications
Middle Tier Development
Web Marketing
Website Optimization
Search Engine Submission
Paid Submission (PPC)
Website Development
Corporate Website
Graphic Design
Logo Design
Database Driven Website
E-Commerce (B2B & B2C)
Flash Website Design
Website Maintains
Brochures Design
Flyer Design
Corporate Identity
ADO.NET
The .NET framework changed the ways we used to access and manipulate the database,
although the fundamental steps of accessing and manipulating the database are not changed.
Thus an ASP.NET application interacts with the ADO.NET objects built into the ADO.NET Model.
Then ADO.NET uses the interface via the .NET manage provider to access the database.
Thus, if your application accesses the Microsoft Access data using ADO objects, and you
upgrade your data to a SQL Server database, you will only need to have a few changes within
your application. The ADO interface to the data will remain the same for most of your
application.
ADO Object Model
The Microsoft ActiveX Data Object Model (ADO) has been the preferred method of
communication with the database. It provided a set objects that were used to open a database
connection, fetch a recordset from the database and perform a set of database operation such
as , display, insert, delete, and update database records.
In the ADO model, when a recordset is being opened, it would keep the connection active with
the database until looping through the recordset is completed. For a Web connection, this
would require a lot of resources for the server when many browsers are communicating with
the server at the same time.
ADO.NET Object Model
The Web itself employs a disconnected client-server approach. That is, after a page is received
from the server, the connection between the browser and the Web server is broken. The
ADO.NET model is built on the same principle. It separates the process of connecting to the
data source from the manipulation of the data.
The ADO.NET model consists of several components, the two central components are: the
DataSet and the .NET Data Provider. The .NET data provider is a set of components including
the Connection, Command, DataReader, and DataAdapter objects.
The ADO.NET DataSet is the core component of the disconnected architecture of ADO.NET. The
DataSet is explicitly designed for data access independent of any data source. As a result it can
be used with multiple and differing data sources, used with XML data, or to manage data local
to the application. The DataSet contains a collection of one or more DataTable objects made up
of rows and columns of data, as well as primary key, foreign key, constraint, and relation
information about the data in the DataTable objects. It replaces the RecordSet object of the
ADO architecture.
The other core element of the ADO.NET architecture is the .NET data provider, whose
components are explicitly designed for data manipulation and fast, forward-only, read-only
access to data. The Connection object provides connectivity to a data source. The Command
object enables access to database commands to return data, modify data, run stored
procedures, and send or retrieve parameter information. The DataReader provides a high-
performance stream of data from the data source. Finally, the DataAdapter provides the bridge
between the DataSet object and the data source. The DataAdapter uses Command objects to
execute SQL commands at the data source to both load the DataSet with data, and reconcile
changes made to the data in the DataSet back to the data source.
Managed Providers (.NET Data provider)
A .NET data provider is used for connecting to a database, executing commands, and retrieving
results. Those results are either processed directly, or placed in an ADO.NET DataSet in order to
be exposed to the user in an ad-hoc manner, combined with data from multiple sources, or
remoted between tiers.
The following table outlines the four core objects that make up a .NET data provider.
Object Description
Connection Establishes a connection to a specific data source.
Command Executes a command against a data source. Exposes Parameters and
can execute within the scope of a Transaction from a Connection.
DataReader Reads a forward-only, read-only stream of data from a data source.
DataAdapter Populates a DataSet and resolves updates with the data source.
The ADO.NET Objects communicate to the data sources through the managed providers. There
are two managed providers in ADO.NET:
SQL Server.NET data provider is used to connect to a SQL Server database version 7.0 or
later. It provides a direct communication with the SQL Server database using a protocol
called TDS (Tabular Data System) which provides performance improvement.
OLE-DB.NET data provider is used to connect to any other data source including SQL
Server, Access database, XML file, or any other database. It does not provide specific
performance improvement.
Driver Provider
SQLOLEDB Microsoft OLE DB Provider for SQL Server
MSDAORA Microsoft OLE DB Provider for Oracle
Microsoft.Jet.OLEDB.4.0 OLE DB Provider for Microsoft Jet (like Access)
The Connection Object
The ADO.Net Connection Object provides the connection to the database. It requires a
connection string that can be written through codes or it can be configured through the Data
Connections window of Visual Studio.NET environment.
The connection string requires the following fields:
Provider The name of the managed provider for the SQL Server or OLE-DB Provider.
Data Source The name of the SQL Server computer or full path of the database like
Access.
Initial Catalog The name of the database in case of database like SQL Server.
User ID and Password It identifies the authentication for databases like SQL Server.
The default user ID in SQL Server is sa and password is blank.
The Command Object
The command object is used to execute a command to process an SQL query, a stored
procedure, or a table from a database. Following are the methods and properties of the
command object.
Connection property - The Connection used by the Command object
CommandText property - identifies the command to execute
CommandType property - indicates the type of command being executed
o Text - by default, indicates that the command is an SQL text string
o TableDirect - specifies the name of a table to return
o StoredProcedure - specifies the name of a stored procedure
ExecuteReader method - executes the command and passes the results to the
DataReader object
ExecuteNonQuery method - does not return rows because its used to insert, modify,
and delete data, but returns an integer of the number of rows affected by the command
The DataReader Object
The data reader object
delivers a stream of data from the database.
provides a high-performance method of accessing read-only data.
read-only, forward-only stream of data from the database.
requires continual access to the database, while the DataAdaptor uses a disconnected
dataset to access the data.
It holds one row in memory at a time, as opposed to DataDet which holds a complete
table in memory.
The methods and properties of DataReader object are:
ExecuteReader method - retrieves rows of data as they are located in the database.
Read - returns a single row and caches each row in memory only once, then moves the
current record pointer to the next record or row.
CommandBehavior property - closes the connection.
Close method - closes the DataReader object and releases the references to the rowset.
The DataAdapter Object
The DataAdapter Object accesses a DataSet object. It is the only way that a database data can
be manipulated (insert, delete, update). Because the DataSet is disconnected, there must be
methods used to maintain the original set of data, and the changes.
The Methods and Properties of the DataAdapter are:
Fill method acts as the bridge between the datasource and the DataSet. It loads the
data stored in the DataAdapter to the DataSet object.
SelectCommand method is used to retrieve data.
InsertCommand method is used to add a new record.
UpdateCommand method is used to modify the data within an existing record.
DeleteCommand method is used to permanently remove a record from the database.
The DataSet Object
The RecordSet object in ADO has been dropped; instead a new object called DataSet is
introduced in ADO.NET.
The DataSet object is a disconnected collection of one or more tables that are stored in
memory.
The DataSet is effectively a private copy of the database in the memory, complete with
tables, columns, relationships, constraints, and data. However, it may not necessarily
reflect the current state of the database.
If you want to see the latest changes made by other users, you can refresh the dataset
by calling the appropriate Fill method of the DataAdapter object.
A DataSet not only can receive data from a database, but also from files such as XML,
text, Excel, and so on.
A DataSet contains a DataTable collection, which in turn contains other collections such as
DataRow, DataColumn, and DataConstraint.
ADO.NET Objects by Data Provider
There are basically four objects in the ADO.NET: Connection, Command, DataReader, and
DataAdapter. Depending on the data provider, the names of these objects are different. There
is also a Dataset object that is part of the ADO.NET object model as shown in the figure. The
names of the objects are different depending on the data provider.
SQL Server .NET data provider
o SqlConnection,
o SqlCommand,
o SqlDataReader, and
o SqlDataAdapter
OLE-DB data provider (like Access)
o OleDbConnection,
o OleDbCommand,
o OleDbDataReader, and
o OleDbDataAdapter.
DataSet object - to retrieve data from the database.
Example
SqlConnection cn = new SqlConnection("server=localhost;initial
catalog=practice;trusted_connection=true");
cn.Open();
SqlCommand cmd = new SqlCommand("select * from product",cn);
SqlDataReader rec = cmd.ExecuteReader();
if (rec.Read())
{
do {
ASP.NET Application
DataReader Object Data Adapter Object
Command Object
Connection Object
Managed Data
Provider
Data Source
DataSet Object
Console.WriteLine("{0},{1},{2}{3}",rec.GetValue(0),rec.GetValue(1),rec.GetValue(2),rec.GetVal
ue(3));
} while (rec.Read());
}
else
{
Console.WriteLine("Record Not Found....");
}
rec.Close();
cn.Close();
Why MVC?
ASP.NET MVC helps to reduce the complexity of the web application by dividing an application
into three layers, Model, View and Controller. This separation (loose coupling) helps in some
long term benefits like isolation of components while development and also
this separation provides better support for test-driven development (TDD). ASP.NET MVC web
site are good in performance and also easy to maintain.
MVC Architecture
The Model-View-Controller (MVC) pattern is an architectural design principle that separates the
application components of a Web application into three layers. This separation gives you more
control over the individual parts of the application, which lets you more easily develop, modify,
and test them.
The Model
Model contains and exposes the properties and application logic In a better way we can say
that The model represents core business logic and data. In the ePhoneBook Sample the
'PhoneBookModel' class represents the properties of a Phone Book in the application and
may expose properties such as First Name, Last Name and Mobile Number etc and also it may
expose methods.
The View
The View is responsible for creating the response HTML or any responses back to the browser
like pdf, html or excel etc. In other way we can sat that the view is responsible for transforming
a model or models into a visual representation.
The Controller
Controller is responsible for processing user inputs from view and give responses back to the
view. It means that the controller decides the action and performs the tasks/logic based on the
parameters.Controller acts as the coordinator between the view and the model.
MVC Interaction with Browser
Like a normal web server interaction, MVC application also accepts requests and responds to
the web browser in the same way.
Inside MVC Architecture
The entire ASP.NET MVC architecture is based on Microsoft .NET Framework 3.5 and in addition
uses LINQ to SQL Server.
What is a Model?
1. MVC model is basically a C# or VB.NET class
2. A model is accessible by both controller and view
3. A model can be used to pass data from Controller to view
4. A view can use model to display data in page.
What is a View?
1. View is an ASPX page without having a code behind file
2. All page specific HTML generation and formatting can be done inside view
3. One can use Inline code (server tags ) to develop dynamic pages
4. A request to view (ASPX page) can be made only from a controllers action method
What is a Controller?
1. Controller is basically a C# or VB.NET class which inherits system.mvc.controller
2. Controller is a heart of the entire MVC architecture
3. Inside Controllers class action methods can be implemented which are responsible for
responding to browser OR calling views.
4. Controller can access and use model class to pass data to views
5. Controller uses ViewData to pass any data to view
MVC File Structure & File Naming Standards
MVC uses a standard directory structure and file naming standards which are a very important
part of MVC application development.
Inside the ROOT directory of the application, there must be 3 directories each for model, view
and Controller.
Apart from 3 directories, there must have a Global.asax file in root folder, and a web.config like
a traditional ASP.NET application.
Root [directory]
o Controller [directory]
Controller CS files
o Models [directory]
Model CS files
o Views [directory]
View aspx/ascx files
o Global.asax
o Web.config
ASP.NET MVC Execution Life Cycle
Here is how MVC architecture executes the requests to browser and objects interactions with
each other.
A step by step process is explained below [Refer to the figure as given below]:
Browser Request (Step 1)
Browser request happens with a specific URL. Lets assume that the user enters URL like:
[xyz.com]/home/index/
Job of Global.asax MVC routing (Step 2)
The specified URL will first get parsed via application_start() method inside Global.asax file.
From the requested URL, it will parse the Controller, Action and ID.
So for [xyz.com]/home/index/:
Controller = home
Action = index()
ID = empty we have not specified ID in [xyz.com]/home/index/, so it will consider as
empty string
Controller and Action methods (Step 3)
MVC now finds the home controller class in controller directory. A controller class contains
different action methods,
There can be more than one action method, but MVC will only invoke the action method which
has been parsed from the URL, its index() in our case.
So something like: homeController.index() will happen inside MVC controller class.
Invoking action method can return plain text string OR rendered HTML by using view.
Call to View (Step 4)
Invoking view will return view(). A call to view will access the particular ASPX page inside the
view directory and generate the rendered HTML from the ASPX and will respond back to the
browser.
In our case, controller was home and action was index(). So calling view() will return a rendered
HTML from the ASPX page located at /views/home/index.aspx.
This is it, the whole process ends here. So this is how MVC architecture works.
Introduction
View Engines are responsible for rendering the HTML from your views to the browser. The view
engine template will have different syntax for implementation. Currently there are few number
of view engines available for MVC and In this article we will go through the Razor and ASPX
view engine
@Razor
The Razor view engine is an advanced view engine from Microsoft, packaged with MVC 3. Razor
using an @ character instead of aspx's <% %> and Razor does not require you to explicitly close
the code-block, this view engine is parsed intelligently by the run-time to determine what is a
presentation element and what is a code element.
In my opinion Razor is the best view engine available for MVC as its much cleaner and easy to
write and read. This view engine is compatible with unit testing frameworks. It is very difficult
to implement unit test with ASPX view engine and the other available view engines doesn't
provide anything related to testablity in their respective sites.
This is the default view engine in MVC 3 and MVC 4. Web pages with Razor syntax have the
special file extension cshtml (Razor with C#) or vbhtml (Razor with VB).
<%ASPX%>
The syntax for writing views with this engine is the same syntax that the ASP.NET Web Forms
uses and the file extensions are also taken from ASP.NET Web Form (.aspx, .ascx, .master) . The
coding will give us the memory of legacy ASP style.
This is the default view engine for MVC 1 and MVC 2.
Let us start exploring the syntax differences and other major points.
Syntax/Usage
If you came from the legacy ASP style coding then you will feel much comfortable with ASPX
View Engine and if you are comfortable with C# language then you can easily go with Razor
view engine. Let's go thrugh how we can use Razor and or ASPX view engine in our application.
Example:
@{
string ViewEngine = "Razor";
string CodeIn = "C#";
string SpanClass = "boldclass";
bool isMale = true;
string[] Products = new string[] { "Computer", "Mobile", "Watch", "Television" };
}
Entity Framework
ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables
developers to work with relational database. It enabling developers to deal with data as objects
and properties.Using the Entity Framework, developers issue queries using LINQ, then retrieve
and manipulate data as strongly typed objects using C# or VB.Net.
The Entity Frameworks ORM implementation also provides services like change tracking,
identity resolution, lazy loading, and query translation so that developers can focus on their
application-specific business logic rather than the data access fundamentals. ADO.NET Entity
Framework is targeted for developing Enterprise applications which can support MS SQL
databases as well as other databases like as Oracle, DB2, MySql and many more. To learn entity
framework first we need to know what is orm.
What is O/RM?
O/RM is an acronym that stands for object/relational mapping. Basically, an O/RM framework is
used to persist model objects in a relational database and retrieve them. It uses metadata
information to interface with the database. This way, your data-layer code knows nothing
about the database structure. The O/RM tool becomes middleware that completely hides the
complexity.
The heart of O/RM is the mappingthe mapping technique is what binds the object and
relational worlds. By mapping, you express how a class and its properties are related to one or
more tables in the database. This information is used by the O/RM tools engine to dynamically
build SQL code that retrieves data and transforms it into objects. Similarly, by tracking changes
to objects properties, it can use mapping data to send updates back to the database. The
mapping information is generally expressed as an XML file. As an alternative, some O/RM tools
use attributes on the classes and their properties to maintain mapping data.
Advantage of Entity Framework
1. Productivity
Entity Framework can take up to 35 percent of the entire application code. It make the
developers life easier than ever. In spite of its limitations, the designer integrated into
Visual Studio dramatically simplifies the mapping process.
2. Maintainability
Since you have the fewer lines of code to fetch data from database,the fewer lines of
code you have to maintain. This is particularly true in the big projects.
3. Performance
The complexity of O/RM introduces an obvious slowdown in performance. In entity
framework first request to fetch data is little bit slow but after that is fast to fetch data
from database.
Entity Framework Models
Microsofts Entity Framework evolved from a methodology known as Entity Relationship
Modeling (ERM). An ERM defines a schema of entities and their relationships with one another.
Entities are not the same as objects. Entities define the schema of an object, but not its
behavior. So, an entity is something like the schema of a table in your database, except that it
describes the schema of your business objects. There are three models in the entity framework:
1. conceptual model
The conceptual model is where you describe the model classes. This file is split into two
main sections: the first is a container that lists all the entities and the relationships that
are managed by Entity Framework, and the second contains a detailed description of
their structure.
2. STORAGE MODEL
The storage model is the equivalent of the conceptual model, but it describes the
database organization. Not only is this file conceptually similar to the previous one, but
it also uses the same XML nodes. Unlike the conceptual model, it isnt possible to split
this model into several physical files. The first section of this file lists all the tables,
views, stored procedures, and foreign keys that are affected. The second section
describes the items listed in the first node.
Regarding tables and views, the columns and primary keys are described. When it
comes to stored procedures, input and output parameters are described. The
description of a foreign key contains information about the table involved, the
cardinality, and the delete and update rules.
3. MAPPING MODEL
The mapping file is completely different. Its job isnt to describe something but to
compensate for the differences that exist between the two previous models. This is
where the real magic of mapping happens: you map a class to one or multiple tables,
map one table to one or multiple classes, define inheritance mapping, and map stored
procedures for both updates and object retrieval.
There is only one important node in this file: it associates the class to a table and can be
repeated more than once to ensure that a class can be mapped against multiple tables,
and vice versa. Like the storage description file and unlike the conceptual file, the
mapping file cant be split into multiple files.
Windows Communication Foundation
WCF stands for Windows Communication Foundation. It is Microsoft's latest technology that
enables applications in a distributed environment to communicate with each other.WCF is
Microsoft's unified programming model for building service-oriented applications. It enables
developers to build secure, reliable, transacted solutions that integrate across platforms and
interoperate with existing.
WCF is an umbrella technology that covers ASMX web services, .NET remoting, WSE, Enterprise
Service, and System.Messaging. It is designed to offer a manageable approach to distributed
computing, broad interoperability, and direct support for service orientation. WCF supports
many styles of distributed application development by providing a layered architecture.
ABC of Windows Communication Foundation
What are the ABCs of WCF? "ABC" stands for address, binding and contract.
1. Address (Where)
It specifies the location of the service means, where the service is hosted. The service
hosting URL may be like http://server/wcfService. Clients will use this location to
communicate with your service.
2. Binding (How)
It specifies how the client will communicate to the service. We have different protocols
(like http,tcp,named pipe,msmq) for the WCF to communicate to the client.
3. Contract (What)
It specifies what the service will do. For this purpose we have different contract like as
Data Contract, Operation Contract, Message Contract, Fault Contract. I will discuss all
these later.
WCF Hosting
A WCF service is a component that can be called by other applications. It must be hosted in an
environment in order to be discovered and used by others. The WCF host is an application that
controls the lifetime of the service. With .NET 3.0 and beyond, there are several ways to host
the service.
1. Self hosting
A WCF service can be self-hosted, which means that the service runs as a standalone
application and controls its own lifetime. This is the most flexible and easiest way of
hosting a WCF service, but its availability and features are limited.
2. Windows services hosting
A WCF service can also be hosted as a Windows service. A Windows service is a process
managed by the operating system and it is automatically started when Windows is
started (if it is configured to do so). However, it lacks some critical features (such as
versioning) for WCF services.
3. IIS hosting
A better way of hosting a WCF service is to use IIS. This is the traditional way of hosting
a web service. IIS, by nature, has many useful features, such as process recycling, idle
shutdown, process health monitoring, message-based activation, high availability, easy
manageability, versioning, and deployment scenarios. All of these features are required
for enterprise-level WCF services.
4. Windows Activation Services hosting
The IIS hosting method, however, comes with several limitations in the service-
orientation world; the dependency on HTTP is the main culprit. With IIS hosting, many
of WCF's flexible options can't be utilized. This is the reason why Microsoft specifically
developed a new method, called Windows Activation Services, to host WCF services.
Windows Process Activation Service (WAS) is the new process activation mechanism for
Windows Server 2008 that is also available on Windows Vista. WAS hosting is possible
only with IIS 7.0.Additional WCF components also plug into WAS to provide message-
based activation over the other protocols that WCF supports, such as TCP, MSMQ
, and named pipes. This allows applications that use the non-HTTP communication
protocols to use the IIS features such as process recycling, rapid fail protection, and the
common configuration systems that were only available to HTTP-based applications.
ASMX-Active Server Methods
WSE- Web Services Enhancements
MSMQ-Microsoft Message Queue
Features of WCF
1. Service Orientation
2. Interoperability
3. Multiple Message Patterns
4. Service Metadata
5. Data Contracts
6. Security
7. Multiple Transports and Encodings
8. Reliable and Queued Messages
9. Durable Messages
10. Transactions
11. AJAX and REST Support
12. Extensibility
HOW WCF SERVICES WORK
Very often we would like to control the way WCF service objects are instantiated on a WCF
server. You would want to control how long the WCF instances should be residing on the
server.
The WCF framework has provided three ways by which we can control WCF instance creation.
In this article, we will first try to understand those three ways of WCF service instance control
with simple code samples of how to achieve them. Finally, we will compare when to use them
and under what situations.
WCF service object instancing basics
In normal WCF request and response communication, the following sequence of actions takes
place:
WCF client makes a request to a WCF service object.
WCF service object is instantiated.
WCF service instance serves the request and sends the response to the WCF client.
Following is a pictorial representation of how WCF requests and responses work.
Following are different ways by which you can create WCF instances:
Create a new WCF service instance on every WCF client method call.
Only one WCF service instance should be created for every WCF client session.
Only one global WCF service instance should be created for all WCF clients.
To meet the above scenarios, WCF has provided three ways by which you can control WCF
service instances:
Per call
Per session
Single instance
Per call instance mode
When we configure a WCF service as per call, new service instances are created for every
method call you make via a WCF proxy client. The image below shows this in a pictorial format:
The WCF client makes the first method call (method call 1).
A new WCF service instance is created on the server for this method call.
The WCF service serves the request and sends the response and the WCF instance is
destroyed and given to the garbage collector for clean up.
Now lets say the WCF client makes a second method call, a new instance is created, the
request is served, and the WCF instance is destroyed.
In other words, for every WCF client method call, a WCF service instance is created, and
destroyed once the request is served.
Per session instance mode
Very often we need to maintain state between method calls or for a particular session. For
those kinds of scenarios, we will need to configure the service per session. In per session, only
one instance of a WCF service object is created for a session interaction. The figure below
explains this in pictorial format.
The client creates the proxy of the WCF service and makes method calls.
A WCF service instance is created which serves the method response.
The client makes one more method call in the same session.
The same WCF service instance serves the method call.
When the client finishes its activity, the WCF instance is destroyed and served to the
garbage collector for clean up.
Single instance mode
Often we would like to create one global WCF instance for all WCF clients. To create a single
instance of a WCF service, we need to configure the WCF service as Single instance mode.
Below is a simple pictorial notation of how the single instance mode will operate:
WCF client 1 requests a method call on the WCF service.
A WCF service instance is created and the request is served. The WCF service instance is
not destroyed, the service instance is persisted to server other requests.
Now lets say some other WCF client, e.g., client 2, requests a method call.
The same WCF instance which was created by WCF client 1 is used to serve the request
for WCF client 2. In other words, only one global WCF server service instance is created
to serve all client requests.