[ServiceContract]
public interface IService1
{
[OperationContract]
void MyOperation1();
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession,ConcurrencyMode=ConcurrencyMode.Multiple)]
public class service1 : IService1
{
public service1()
{
Console.WriteLine("creating instance");
}
public void MyOperation1()
{
Console.WriteLine("starting..");
Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(1000);
Console.WriteLine("Ending..");
}
}I have a client code:
static void Main(string[] args)
{
Thread[] t = new Thread[10];
NetTcpBinding myBinding = new NetTcpBinding();
EndpointAddress myEndpoint = new EndpointAddress("net.tcp://localhost:8000/MyService");
ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint);
IService1 instance = myChannelFactory.CreateChannel();
for (int i = 0; i < 10; i++)
{
t[i] = new Thread(new ThreadStart(delegate()
{
instance.MyOperation1();
}));
}
for (int i = 0; i < 10; i++)
{
t[i].Start();
}
}My calls to service are being proccessed one by one. Can I get the calls concurrently processed?
Hemant SrivastavaPosted Aug 8, 2013, 9:08 AM
Per call
•You want a stateless services.
•Your service holds intensive resources like connection objects and huge memory objects.
•Scalability is a prime requirement. You would like to have a scaled out architecture.
•Your WCF functions are called in a single threaded model.
Per session
•You want to maintain states between WCF calls.
•You a scaled up architecture.
•Light resource references.
Single
•You want share global data through your WCF service.
•Scalability is not a concern.
Refer to article for more detail:
http://www.codeproject.com/Articles/86007/3-ways-to-do-WCF-instance-management-Per-call-Per
Hemant SrivastavaPosted Aug 8, 2013, 8:55 AM
Debdeep BhattacharyyaPosted Aug 7, 2013, 5:22 PM
I need the service to act concurrently for each session.
Hemant SrivastavaPosted Aug 7, 2013, 4:17 PM
InstanceContextMode = InstanceContextMode.PerCall