WCF Callbacks, Proxies, and Thread Safety

For the WCF duplexer service (NetTcpBinding), which is configured to create a new service instance for each new client (see the publication-subscription template ), you can get a specific callback instance for each service instance. Because different instances are created, methods related to different callbacks can be called from different threads at the same time.

  • What happens if multiple threads try to call the same method in a single callback?
  • What happens if they try to call different methods, but for the same callback?
  • Should we control concurrent access to these methods from multiple threads? In both cases?

Now consider the client side that communicates with the service: in order for the client to use this service, you must create an instance of a new proxy, and to call the methods defined in the service, you must call the corresponding proxy methods.

  • What happens if multiple threads try to call the same method on the same proxy instance?
  • What happens if they try to call different methods, but for the same proxy instance?
  • Should we control concurrent access to these methods from multiple threads? In both cases?
+5
source share
1 answer

, concurrency. , , ConcurrencyMode InstanceContextMode. WCF concurrency . MSDN ( ) , concurrency.

InstanceContextMode . , , PerCall instancing, .

ConcurrencyMode, , , . ConcurrencyMode=Single . , SynchronizationConext, SynchronizationConext=true, , . , , . ConcurrencyMode=Multiple , , , , ( ) . concurrency , , , , SynchronizationContext false. MSDN concurrency .

InstanceContext, . , concurrency ( , , , , IIS).

concurrency . ( ThreadPool) , , . , .

+6

All Articles