none
WCF request queuing RRS feed

  • Question

  • I have a WCF service which creates a number of files at a server location doing various calculation on seed file depending upon the params given. The problem is that, the when 2 or more clients try to do calculation on same seed file, it is returning error. The cause is simply due to read/write access by multiple users at a time. 
    So I want to create a user request queue in WCF from where server does its calculation one at a time and returns calculated response to the user. The problem is I don't know how to do it. 

    I have not implemented any request queue technique in WCF before. Does anyone know how to implement this in WCF Services. I cannot do threading as calculation depends upon the file I/O so handling one request at a time is only one solution at this time.

    Any tutorial or video tutorial will be highly appreciated.

      

    Saugat K.C.

    Monday, May 25, 2015 4:43 AM

Answers

  • Finally I did it. Here I am posting my soluton for other users who may be new to the WCF request queuing. At first, we need to implement the throttling settings in WCF host file. Throttling can be done in two ways (Either way is OK):

    1. Config file
    2. Code

    Throttling settings in config file as follows:

    [behaviors] [serviceBehaviors] [behavior name="throttlingBehavior"] [serviceThrottling maxConcurrentCalls="3" maxConcurrentInstances="3" maxConcurrentSessions="100"/] [/behavior] [/serviceBehaviors] [/behaviors]

    Or throttling settings in code

    using (ServiceHost host = new ServiceHost(typeof(SimpleService.SimpleS­ervice)))
    { 
    ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = 3, MaxConcurrentInstances = 3, MaxConcurrentSessions = 100 }; 
    host.Description.Behaviors.Add(throttlin­gBehavior); 
    host.Open(); 
    Console.WriteLine("Host started @ " + DateTime.Now.ToString()); 
    Console.ReadLine();
    }

    With the above throttling settings a maximum of 3 concurrent calls are processed. In addition to maxConcurrentCalls property, maxConcurrentInstances and maxConcurrentSessions may also impact the number of calls processed concurrently.

    Now after defining throttling behavior, we need to define concurrency mode in service contract as follows:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,ConcurrencyMode=ConcurrencyMode.Multiple)]
    public class Service:IService
    {...

    With these settings in placed, we can easily get the the request queuing in WCF service.


    Saugat K.C.

    • Marked as answer by Saugat331 Monday, May 25, 2015 8:58 AM
    Monday, May 25, 2015 8:57 AM

All replies

  • Finally I did it. Here I am posting my soluton for other users who may be new to the WCF request queuing. At first, we need to implement the throttling settings in WCF host file. Throttling can be done in two ways (Either way is OK):

    1. Config file
    2. Code

    Throttling settings in config file as follows:

    [behaviors] [serviceBehaviors] [behavior name="throttlingBehavior"] [serviceThrottling maxConcurrentCalls="3" maxConcurrentInstances="3" maxConcurrentSessions="100"/] [/behavior] [/serviceBehaviors] [/behaviors]

    Or throttling settings in code

    using (ServiceHost host = new ServiceHost(typeof(SimpleService.SimpleS­ervice)))
    { 
    ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = 3, MaxConcurrentInstances = 3, MaxConcurrentSessions = 100 }; 
    host.Description.Behaviors.Add(throttlin­gBehavior); 
    host.Open(); 
    Console.WriteLine("Host started @ " + DateTime.Now.ToString()); 
    Console.ReadLine();
    }

    With the above throttling settings a maximum of 3 concurrent calls are processed. In addition to maxConcurrentCalls property, maxConcurrentInstances and maxConcurrentSessions may also impact the number of calls processed concurrently.

    Now after defining throttling behavior, we need to define concurrency mode in service contract as follows:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,ConcurrencyMode=ConcurrencyMode.Multiple)]
    public class Service:IService
    {...

    With these settings in placed, we can easily get the the request queuing in WCF service.


    Saugat K.C.

    • Marked as answer by Saugat331 Monday, May 25, 2015 8:58 AM
    Monday, May 25, 2015 8:57 AM
  • Hi Saugat331,

    Well Done!

    Thank you very much for sharing the solution to us. :)

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 26, 2015 1:50 AM
    Moderator