在使用WCF会话 [英] Using the Session in WCF
本文介绍了在使用WCF会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面就是我试图做使用会话
在我的WCF应用程序:
Here's what I'm trying to do to use the Session
in my WCF application:
System.Guid guid = System.Guid.NewGuid();
string id = guid.ToString();
HttpContext.Current.Session[id] = "AnyThing";
但我收到此错误消息:
But I'm receiving this error message:
对象引用未设置为对象的实例。
Object Reference not set to instance of Object.
这是使用正确的方法会话
在WCF应用程序? ?还是有另一种方式来储存在WCF数据
Is this the right approach for using the Session
in a WCF application? Or is there another way to store data within WCF?
推荐答案
您将需要启用的 ASP.NET兼容模式
的web.config
web.config
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
您WCF服务需要具备的 AspNetCompatibilityRequirementsAttribute 的设置要求或允许。
Your WCF services need to have the AspNetCompatibilityRequirementsAttribute set to Required or Allowed.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class CalculatorService : ICalculatorSession
这篇关于在使用WCF会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文