WCF 请求处理线程是否敏捷?

发布于 2024-08-23 21:22:10 字数 164 浏览 4 评论 0原文

我看过很多关于敏捷 Asp.Net 请求处理如何的文档?我想知道 WCF 请求处理的情况是否相同。我们可以相信启动 Wcf 请求处理的线程将完成它吗?

我正在维护一个 Wcf 应用程序,其中很多地方都使用 ThreadStatic 变量。虽然代码可以工作,但是它可靠吗?值得改变它还是应该保持原样?

I have seen lots of documentation on how Agile Asp.Net Request handling is? I want to know is the case same with WCF Request handling. Can we rely on the fact that the Thread that starts Wcf request handling will finish it?

I am maintaining a Wcf Application where at lots of places ThreadStatic variables are used. Although the code is working but is it reliable? Is it worth changing it or should I keep it as it is?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野心澎湃 2024-08-30 21:22:10

创建 WCF 服务时,您可以通过使用 ServiceBehavior 属性装饰服务实现类来设置线程和服务实例化行为:


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

上面的代码片段来自 http: //msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx

编辑
我进行了更多研究,发现了这篇文章:http://blogs.microsoft.co.il/blogs/applisec/archive/2009/11/23/wcf-thread-affinity-and-synchronization.aspx。它基本上说不,您不能确定启动请求的同一线程将是完成请求的线程。

编辑 2
这个问题之前已在 StackOverflow 讨论过。它链接到 如何创建 WCF 服务 STA(单线程) 其中有关于如何创建将强制使用单线程单元的操作行为的描述。该示例涉及调用 GUI 组件,但它也应该适用于其他单线程需求。

When creating a WCF service you can set the threading and service instantiating behaviour, by decorating the service implementation class with a ServiceBehavior attribute:


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

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

EDIT
I dit a bit more research and found this article: http://blogs.microsoft.co.il/blogs/applisec/archive/2009/11/23/wcf-thread-affinity-and-synchronization.aspx. It basically says that no, you cannot be sure that the same thread starting the request will be the one finishing it.

EDIT 2
This question has been discussed before at StackOverflow. It links to How to make a WCF service STA (single-threaded) where there is a description on how to create an OperationBehavior which will force a single threaded apartment. The example deals with calling GUI components, but it should work for other single threaded requirements as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文