WCF requests handle Thread Agile?

I saw a lot of documentation on how Agile Asp.Net Request is handled? I want to know, just like with WCF request processing. Can we rely on Thread starting Wcf request processing to complete it?

I support the Wcf application, where ThreadStatic variables are used in many places. Although the code works, is it reliable? Should I change it or should I keep it as it is?

+4
source share
1 answer

When creating a WCF service, you can set the thread creation and maintenance behavior by decorating the service implementation class with the ServiceBehavior attribute:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
class SingleCachingHttpFetcher : IHttpFetcher

The above code snippet is at http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx

<i> CHANGE
I researched a bit more and found this article: http://blogs.microsoft.co.il/blogs/applisec/archive/2009/11/23/wcf-thread-affinity-and-synchronization.aspx . This basically says no, you cannot be sure that the same thread starting with the request will be the one that ends it.

EDIT 2
This issue was discussed earlier at fooobar.com/questions/562149 / .... He refers to How to make a WCF STA service (single-threaded) , where there is a description of how to create an OperationBehavior that will force a single-threaded apartment. This example looks at GUI component calls, but they should work for other single-threaded requirements.

+4
source

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


All Articles