如何并发工作的WCF? [英] How does Concurrency work in WCF?

查看:150
本文介绍了如何并发工作的WCF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:我是一个新手,在WCF和SOA:P

Disclaimer : I am a novice in WCF and SOA :P

我刚开始就这些,我有一个理论上的疑问:

I am just starting out on these, I have a theoretical doubt :

客户端A也称为服务和逻辑当前正在执行的服务器上。虽然逻辑执行,从客户端B另一个电话打进来了同样的服务。

Client A has called a service and the logic is currently executing on the server. While the logic is executing, another call from Client B comes in for the same service.

在这一点恰好是正在为客户端A执行的逻辑是什么?如何服务管理服务这两种请求?

At this point what happens to the logic that is being executed for Client A ? How does the service manage to serve both the requests ?

推荐答案

回答你的问题取决于你正在使用绑定。有两种设置控制这种行为:InstanceContextMode和ConcurrencyMode。这两种设置都在ServiceBehaviorAttribute设置。

Answer to your question depends on binding you are using. There are two settings controlling this behavior: InstanceContextMode and ConcurrencyMode. Both these settings are set in ServiceBehaviorAttribute.

InstanceContextMode控制服务是如何被实例化。它具有以下值:

InstanceContextMode controls how the service is instantiated. It has following values:

  • PerCall - 每次调用创建服务新服务实例的时间。这是暴露在绑定不使用传输会话,可靠的会话或安全会话=> basicHttpBinding的,的WebHttpBinding服务的默认行为。

  • PerCall - each time you call the service new service instance is created. This is default behavior for services exposed on bindings which don't use transport session, reliable session or security session => BasicHttpBinding, WebHttpBinding.

PerSession - 每次调用新的代理实例新的服务实例的服务时创建。从相同的代理的任何后续呼叫由相同的服务实例处理(例如住在服务器上)。缺省情况下随后的呼叫必须10分钟(receiveTimeout)或服务实例中完成的被释放。这是暴露在绑定服务,使用传输会话的缺省默认行为,可靠的使sesion或安全会话=> WsHttpBinding的(默认设置使用安全会议),NetTcpBinding的,NetNamedPipeBinding。

PerSession - each time you call the service from new proxy instance new service instance is created. Any subsequent call from the same proxy is handled by the same service instance (instance lives on the server). By default subsequent call has to be done within 10 minutes (receiveTimeout) or service instance is released. This is default default behavior for services exposed on binding which use transport session, reliable sesion or security session => WSHttpBinding (default setting uses security session), NetTcpBinding, NetNamedPipeBinding.

单 - 服务只有一个实例存在,并且处理所有来电。该服务实例可以被创建时,主机启动时或服务被称为第一次。

Single - only one instance of the service exists and it handles all calls. This service instance can be created when host starts or when service is called first time.

现在你知道如何实例被创建。第二个设置ConcurrencyMode控制多少个并发线程可以访问单个实例。每个请求总是在单独的线程来处理。

Now you know how instances are created. The second setting ConcurrencyMode controls how many concurrent threads can access single instance. Each request is always handled in separate thread.

  • 单 - 只有一个线程可以访问服务实例。这是默认的行为。

  • Single - only one thread can access service instance. This is default behavior.

折返 - 一个线程可以访问服务,但是,但它可以释放锁,并允许其他线程使用的实例而firts线程将被阻止。这用在回调方案。

Reentrant - one thread can access service but but it can release the lock and allow other thread to use the instance while firts thread will be blocked. This is used in callback scenario.

多 - 多线程可以访问服务实例。

Multiple - multiple threads can access service instance.

现在你知道如何实例可以同时使用。让我们对一些组合一起来看看:

Now you know how instance can be concurrently used. Lets have a look on some combinations:

  • PerCall实例化+单并发 - 典型的无状态的情形。多个并发呼叫是允许的。

  • PerCall instancing + Single concurrency - typical stateless scenario. Multiple concurrent calls are allowed.

PerCall实例化+多并发 - 没有任何意义。它仍然表现得像单并发。

PerCall instancing + Multiple concurrency - doesn't make sense. It still behaves like Single concurrency.

PerSession实例化+单并发 - 从每个代理的多个并发呼叫被允许,但只有一个呼叫可以在同一时间内处理。其他的呼叫进行排队。

PerSession instancing + Single concurrency - multiple concurrent calls are allowed but only single call from each proxy can be processed at the same time. Other calls are queued.

PerSession实例存储+多并发 - 多个并发调用是允许的。从每个代理多个呼叫可以同时访问同一个实例。你所要做的访问在服务实例共享领域的手动同步。

PerSession instancing + Multiple concurrency - multiple concurrent calls are allowed. Multiple calls from each proxy can access same instance at the same time. You have to do manual synchronization of access to shared fields in the service instance.

单实例+单并发 - 只有一个请求可以及时处理。其他请求被排队(默认超时30秒)。

Single instancing + Single concurrency - only single request can be processed at time. Other requests are queued (default timeout 30s).

单实例存储+多并发 - 多个并发调用是允许的。所有来电访问在同一时间同一个实例。你所要做的访问在服务实例共享领域的手动同步。

Single instancing + Multiple concurrency - multiple concurrent calls are allowed. All calls access same instance at the same time. You have to do manual synchronization of access to shared fields in the service instance.

这篇关于如何并发工作的WCF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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