0
Answer

WCF: Configure server-side call handling synchronization type at method level?

Ask a question
Huck

Huck

16y
3.1k
1
Hi, I am using WCF in a client-server architechture, my server has a UI and is configured as follows:

[ServiceBehavior(UseSynchronizationContext = true, InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]

This means all calls made from my clients are handled on the server's UI thread, one after the other. This makes sense in the context of my application, but I have one particular two-way call that is quite lenghty and thread safe (reentrant). I would therefore like my server to handle that specific method call asynchronously, but to keep all other client calls handling synchronous in the server's UI thread. Please note that this is a server-side issue, I want to achieve this no matter how the clients call my server (synchronously or asynchronously).

Here are my questions:

1) Is it possible to configure my server to execute the client calls in its UI thread (UseSynchronizationContext = true), but to override that behavior on a per-call basis to specify a few methods that should be handled asynchronously?

2) If it is possible to configure the synchronization mode at the method level, can it be done in the config file of my server?

Thanks in advance.