Destroy wcf stream

I use multi-threaded wcf maxConcurrentCalls = 10. When registering calls to my service, I see that in my class of service 10 different threads are running and they are reused in the following calls.

Is it possible to tell WCF about thread deletion / deletion so that it creates a new one on the next call?

This is because I have a static state that I sometimes want to clear (with unexpected exceptions). I use thread-static scope to improve performance.

0
source share
1 answer

WCF does not create new threads. It uses threads from a thread pool to serve requests. Therefore, when the request begins, it pulls the stream from this pool to execute the request and, after its completion, returns the stream to the pool. The way WCF uses the streams below is an implementation detail you cannot rely on. You should never use Thread Static in ASP.NET/WCF to store state.

In ASP.NET you must use HttpContext.Items and in WCF OperationContext to store some state that will be available throughout the request.

Here's a good blog post, you can take a look at what a good way to abstract that illustrates.

+1
source

Source: https://habr.com/ru/post/1242681/


All Articles