Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF InstanceContextMode.Multiple issues

So I'm hosting WCF service in a WinForms application. I have the following

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, 
         InstanceContextMode = InstanceContextMode.PerCall)]
public class Test : ITest
{
    public string TestIt(string input)
    {
        Thread.Sleep(5000);
        return "test";
    }
}

I'm using Named Pipes and have two instances of another application that act as clients to the above WCF service (running in a WinForms application). I thought based on the ConcurrencyMode setting of Multiple that when Client1 calls the Test Service, Client2 doesn't have to wait till the first call is complete. However, when Client1 calls TestIt, Client2 blocks until the call from Client1 is complete!?!?! Shouldn't it make a new instance each time based on the above settings?

Also, is the best way to keep a WinForms application that is hosting a WCF service responsive is by running the WCF service on a separate thread?

NOTE: Setting [CallbackBehavior(UseSynchronizationContext = false)] on the Test class does not alleviate the problem. The service still only responds to one request at a time.

like image 775
AKoran Avatar asked Dec 07 '22 08:12

AKoran


1 Answers

Sounds like you want to set this

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.usesynchronizationcontext.aspx

to false. By default, if there is a synchronization context when service.Open() happens, WCF will pick it up and use it. But if you don't want that feature, this flag is how to turn it off.

like image 161
Brian Avatar answered Jan 18 '23 22:01

Brian