wcf - WCF 中的实例停用是什么?

标签 wcf

我最近遇到了术语Instance Deactivation

a) 那是什么?

b) 我们需要它做什么?

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

我正在寻找一个简单的答案,它很容易让人难以理解,如果可能的话,可以使用一些伪代码。

谢谢

最佳答案

当调用 WCF 方法时,它会传递给服务实例

Instance Deactivation 只是指 WCF 系统处理该实例的时刻。

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

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

在单例服务中,实例停用将在服务主机关闭时发生。

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

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

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

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

Juval Lowy关于您是否应该手动覆盖标准实例停用机制有这样的说法:

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 - WCF 中的实例停用是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3597699/

相关文章:

c# - 控制台托管 WCF 服务 Http 可在 mono 和 IIS 下访问

wcf - 在自定义 IIS 帐户下运行的远程调试 WCF 服务

WCF Web 服务中的 C# bool 变量始终为 false/Datetime 变量始终为 DateTime.Min

c# - 捕获多个自定义FaultException类型

c# - 如何使用 azure、wcf、asp.net 和 json 创建应用程序

WCF故障异常不会在客户端上显示 SOAP 服务的详细信息

c# - 从 C# 调用 OData 服务

c# - 如何从 Services .NET 中过滤掉 WCF 异步方法

c# - WCF 超时太快 & 'Connection was closed unexpectedly' 异常

c# - (错误)使用 C# 迭代器实现协程的陷阱