什么是 WCF 中的实例停用? [英] What is Instance Deactivation in WCF?

查看:31
本文介绍了什么是 WCF 中的实例停用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了术语Instance Deactivation.

a) 那是什么?

b) 我们需要什么?

c) 它在什么情况下有用?

c) In what context will it be useful?

我正在寻找一个简单的答案,该答案很容易令人难以理解,并且可以使用一些伪代码.

I am looking for a simple answer that can be easily undestandable and if posible with some pseudo code.

谢谢

推荐答案

当一个 WCF 方法被调用时,它被传递到一个服务实例.

When a WCF method is invoked, it is passed to a service instance.

实例停用只是指 WCF 系统处理此实例的时刻.

Instance Deactivation simply refers to the moment where the WCF system disposes of this instance.

在 Per-Call Service 中,实例停用将在每次方法调用后发生.

In a Per-Call Service, instance deactivation will occur after each method call.

在 Per-Session Service 中,当客户端调用代理上的 Close 或达到传输会话的不活动超时时,实例停用将发生.

In a Per-Session Service, instance deactivation will occur when the client calls Close on the proxy, or when the transport-session's inactivity timeout is reached.

在单例服务中,当服务主机关闭时会发生实例停用.

In a Singleton Service, instance deactivation will occur when the Service Host is closed.

您还可以配置单独的服务方法来触发实例停用:.

You can also configure individual service methods to trigger instance deactivation:.

[OperationBehavior(ReleaseInstanceMode = ReleaseInstanceMode.AfterCall)]
 public void MyMethodWhichTriggersAnAutomaticRelease()
 {
     // ...
 }

除此之外,您还可以手动触发服务实例发布:

As well as this, you can manually trigger a service instance release:

public void MyMethodWhichTriggersAManualRelease()
{
     OperationContext.Current.InstanceContext.ReleaseServiceInstance();
}

Juval Lowy 对此有话说您是否应该手动覆盖标准实例停用机制:

Juval Lowy has this to say on whether you should manually override the standard instance deactivation mechanisms:

实例停用是一个优化技术,和所有的一样优化技术,你应该在一般情况下避免它.考虑仅在之后使用实例停用未能同时满足您的表现和可扩展性目标以及谨慎时检查和分析已经证明毫无疑问,使用实例停用将改善情况.

Instance deactivation is an optimization technique, and like all optimization techniques, you should avoid it in the general case. Consider using instance deactivation only after failing to meet both your performance and scalability goals and when careful examination and profiling has proven beyond a doubt that using instance deactivation will improve the situation.

这篇关于什么是 WCF 中的实例停用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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