从WebHttpBinding访问WCF服务中的会话

Jac*_*tor 6 asp.net wcf

我正在使用WCF服务(通过WebGet属性).

我正在尝试从WCF服务访问Session,但HttpContext.Current为null

我添加了AspNetCompatibilityRequirements并编辑了web.config但我仍然无法访问会话.

是否可以一起使用WebGet和Session?

谢谢!

Wik*_*hla 5

对的,这是可能的.如果你编辑web.config:

<system.serviceModel>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

并添加AspNetCompatiblityRequirements,HttpContext.Current应该是可用的.

再次检查所有内容,也许你已将属性放在错误的位置(界面而不是类?).

  • 我有属性,但没有会话.WebHttpBinding与会话兼容吗? (2认同)