Question Arises: What is Instance
Management?
We can say it is a type of rules governed to manage the services with clients.
It provides high end in scalability, durability and effective transaction
management.
Question Arises: What is Per-Call Based Instance Management?
Basically, we can say every time a new service instance will be created when the
client makes request. Based on the client request the method returns desired
response back to client. Once the response is sent back to client, the dispose
method will we will be declaring in this application releases the instances.
So, let's try to implement this concept so that we can get much better idea on
this:
So, firstly we will create simple method in IService1, Where the Complete Code
of IService1.cs looks like this:
using
System.ServiceModel;
namespace
SimpleInstanceManagement
{
// NOTE: You can use the "Rename"
command on the "Refactor" menu to change the interface name "IService1" in both
code and config file together.
[ServiceContract]
public
interface
IService1
{
[OperationContract]
int SimpleMethod(int
a);
}
}
The Complete Code of Service1.svc looks like this:
using
System;
using
System.ServiceModel;
namespace
SimpleInstanceManagement
{
// NOTE: You can use the "Rename"
command on the "Refactor" menu to change the class name "Service1" in code, svc
and config file together.
[ServiceBehavior(InstanceContextMode =
InstanceContextMode.PerCall)]
public
class Service1
: IService1, IDisposable
{
public
int Heighter = 0;
public
int SimpleMethod(int
a)
{
a = (Heighter
= Heighter + 1); return a;
}
public
void Dispose()
{
Heighter =
Heighter - 1;
}
}
}
The Complete Code of Web.Config looks like this:
<?xml
version="1.0"?>
<configuration>
<system.web>
<compilation
debug="true"
targetFramework="4.0"
/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior
name="Application">
<!--
To avoid disclosing metadata information, set the value below to false and
remove the metadata endpoint above before deployment
-->
<serviceMetadata
httpGetEnabled="true"/>
<!--
To receive exception details in faults for debugging purposes, set the value
below to true. Set to false before deployment to avoid disclosing exception
information
-->
<serviceDebug
includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
multipleSiteBindingsEnabled="true"
/>
<services>
<service
name="SimpleInstanceManagement.Service1"
behaviorConfiguration="Application">
<endpoint
address="/SimpleAddress"
binding="basicHttpBinding"
contract="SimpleInstanceManagement.IService1">
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add
baseAddress="http://localhost:49257/Service1.svc"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules
runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I have created New Web Application where I have added it to existing solution
files. I have specified service reference with a link as given below:
http://localhost:49257/Service1.svc
The Complete Code of WebForm1.aspx looks like this:
<%@
Page Language="C#"
AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs"
Inherits="Instance.WebForm1"
%>
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.



James VeronicaPosted Dec 22, 2011, 6:35 AM
Nice post Vijay, keep it up. You can visit here as well, suggestions and feedback are being awaited http://www.codinghub.net/2011/12/wcf-tutorial-session-management-in-wcf.html
Stephen JohnsonPosted Dec 19, 2011, 11:55 PM
Hi Vijay.Nice article.
Arjun PanwarPosted Dec 19, 2011, 11:52 PM
Thanks for sharing this article