WCF中的国家管理 [英] State Management in WCF

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

问题描述

大家好,

我正在进行一个迁移项目,我正在将一个Web服务(.asmx)重新连接到WCF服务。



我的旧服务有这样的代码。

Hi All,
I am working on a migration project in which I am rewriiting a web service (.asmx) to a WCF service.

My old service has some code like this.

Application[strSession] = LstUserSessionTrack;





上面的代码使用ASP.NET的Application对象来维护状态。 WCF中没有应用程序对象。



我在WCF中寻找一些等同于Application对象的对象。我想在WCF中实现状态管理。 br $> b $ b

请建议。



谢谢。



快乐编码

推荐答案





你不要在WCF中为应用程序提供直接等价物。



但是你可以使用ServiceBehavior中的InstanceContextMode.PerSession维护每个会话的状态,如下所示:



Hi,

You don't have direct equivalent in WCF for an Application.

But you can maintain state per session with InstanceContextMode.PerSession in ServiceBehavior like this:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service : IService
{
}





WCF将创建客户发起的每个会话的实例。您可以控制服务合同,该操作正在启动



WCF will create instance for each session initiated by your clients. You can control on a service contract which operation is initiating

[OperationContract(IsInitiating = true)]

并且正在终止

[OperationContract(IsTerminating = true)]





你也可以使你的服务实现类是一次性的,所以会话结束后,WCF将调用Dispose方法。



最后一件事 - 您必须选择支持会话的绑定,例如NetHttpBinding。



祝你好运,



Michael Parshin



You can also make your service implementation class disposable, so WCF will call Dispose method whenever session is ended.

Last thing - you have to choose binding that supports sessions, like NetHttpBinding for instance.

Good luck,

Michael Parshin


这篇关于WCF中的国家管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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