WCF Data Services & multithreading RRS feed

  • Question

  • Hello,

    I struggle to enable multithreading behavior on self-hosted WCF DataService and I have no more ideas where to dig.

    It seems that ConcurrencyMode.Multiple has no effect on DataService declaration (though, different InstanceContextMode settings work) which leads to queueing queries from clients and processing them one-by-one on server-side. Each request creates new DataServiceContext but only after the previous one is completed.

    I use standard auto-generated proxy on client-side and custom DataServiceContext on server-side if that makes any difference. Binding is webHttpBinding with default settings.

    Any clues would be very appreciated, thanks in advance.

    Monday, August 13, 2012 2:42 PM


  • The thing I was missing is [ServiceBehavior(UseSynchronizationContext = false)].

    When set to true (by default) this causes DataService instance to run in the thread it was created (in case of self-hosted service - UI main thread) thus all requests should have waited until the thread is free again.

    Now a separate thread created for every DataService instance and all works fine.

    Please, close the topic.

    • Marked as answer by Igor Rybalka Tuesday, August 14, 2012 1:27 PM
    Tuesday, August 14, 2012 1:27 PM