WCF服务,为每个新请求创建一个新线程 [英] WCF Service which creates a new thread for every new request

查看:57
本文介绍了WCF服务,为每个新请求创建一个新线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以配置WCF服务以创建新线程来处理任何新的传入请求?

Is there a way to configure a WCF Service to create a new Thread to handle any new incoming request?

推荐答案

是的,您可以这样做-称为按呼叫"请求处理.ServiceHost将为处理该请求的每个请求创建服务类的新实例.

Yes you can do that - it's called "per-call" handling of requests. The ServiceHost will create a new instance of your service class for each request coming in to handle that one request.

为此,您需要将您的Service类(实现服务接口的那个)设置为"PerCall"-您可以通过在服务类上应用属性来做到这一点:

To do this, you need to set your Service class (the one implementing the service interface) to be "PerCall" - you do this by applying an attribute on your service class:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class YourService : IYourService
{
...
}

马克

这篇关于WCF服务,为每个新请求创建一个新线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆