Wcf Concurrency mode

Concurrency is the control of the number of threads active in an InstanceContext at any one time.

Single: – A single request has access to the WCF service object at a given moment of time. So only one request will be processed at any given moment of time. The other requests have to wait until the request processed by the WCF service is not completed.

Multiple: – In this scenario multiple requests can be handled by the WCF service object at any given moment of time. In other words request are processed at the same time by spawning multiple threads on the WCF server object.
So you have great a throughput here but you need to ensure concurrency issues related to WCF server objects.

Reentrant: – A single request thread has access to the WCF service object, but the thread can exit the WCF service to call another WCF service or can also call WCF client through callback and reenter without deadlock.

For example :
In IService

[ServiceContract]
public interface IService1
{

[OperationContract(IsOneWay=true)]
void call(string name);
}

 [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)]
public class Service : IService
{

int count;

public void call(string name)
{
count++;
Console.WriteLine(“client name : ” + name + ” instance : ” +count.ToString() + ” Tread : ” +Thread.CurrentThread.ManagedThreadId.ToString()+ ” Time : ” + DateTime.Now.ToString() );

Thread.Sleep(5000);

}

}

In the client :

static void Main(string[] args)
{
ServiceReference1.Service1Client obj = new ConsoleClient.ServiceReference1.Service1Client();
for (int i = 0; i < 5; i++)
{
obj.call(“client”);
}
Console.ReadLine();
}

 

Refer link: http://www.codeproject.com/KB/WCF/WCFConcurrency.aspx?display=Mobile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s