I'm using WCF service (via WebGet attribute).
我正在使用WCF服务(通过WebGet属性)。
I'm trying to access Session from WCF service, but HttpContext.Current is null
我正在尝试从WCF服务访问Session,但HttpContext.Current为null
I added AspNetCompatibilityRequirements and edited web.config but I still cannot access session.
我添加了AspNetCompatibilityRequirements并编辑了web.config但我仍然无法访问会话。
Is it possible to use WebGet and Session together?
是否可以一起使用WebGet和Session?
Thank you!
2 个解决方案
#1
5
Yes, it is possible. If you edit the web.config
:
对的,这是可能的。如果您编辑web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
and add the AspNetCompatiblityRequirements
, the HttpContext.Current
should be available.
并添加AspNetCompatiblityRequirements,HttpContext.Current应该可用。
Check everything once again, maybe you've put the attribute in the wrong place (the interface instead of the class?).
再次检查所有内容,也许你已将属性放在错误的位置(界面而不是类?)。
#2
4
A RESTfull service with a session?
带会话的RESTfull服务?
See excellent discussion here: Can you help me understand this? "Common REST Mistakes: Sessions are irrelevant"
在这里看到很好的讨论:你能帮助我理解这个吗? “常见的REST错误:会话无关紧要”
http://javadialog.blogspot.co.uk/2009/06/common-rest-mistakes.html (point 6)
http://javadialog.blogspot.co.uk/2009/06/common-rest-mistakes.html(第6点)
and
http://www.peej.co.uk/articles/no-sessions.html
Quote from Paul Prescod:
保罗·普雷斯科德的报价:
Sessions are irrelevant.
会话无关紧要。
There should be no need for a client to "login" or "start a connection." HTTP authentication is done automatically on every message. Client applications are consumers of resources, not services. Therefore there is nothing to log in to! Let's say that you are booking a flight on a REST web service. You don't create a new "session" connection to the service. Rather you ask the "itinerary creator object" to create you a new itinerary. You can start filling in the blanks but then get some totally different component elsewhere on the web to fill in some other blanks. There is no session so there is no problem of migrating session state between clients. There is also no issue of "session affinity" in the server (though there are still load balancing issues to continue).
客户端不需要“登录”或“启动连接”。 HTTP验证在每条消息上自动完成。客户端应用程序是资源的消费者,而非服务。因此没有什么可登录的!假设您在REST网络服务上预订航班。您不创建与服务的新“会话”连接。而是你要求“行程创建者对象”为你创建一个新的行程。您可以开始填充空白,然后在网络上的其他地方获得一些完全不同的组件以填充其他一些空白。没有会话,因此在客户端之间迁移会话状态没有问题。服务器中也没有“会话亲和性”问题(尽管仍有负载平衡问题需要继续)。
#1
5
Yes, it is possible. If you edit the web.config
:
对的,这是可能的。如果您编辑web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
and add the AspNetCompatiblityRequirements
, the HttpContext.Current
should be available.
并添加AspNetCompatiblityRequirements,HttpContext.Current应该可用。
Check everything once again, maybe you've put the attribute in the wrong place (the interface instead of the class?).
再次检查所有内容,也许你已将属性放在错误的位置(界面而不是类?)。
#2
4
A RESTfull service with a session?
带会话的RESTfull服务?
See excellent discussion here: Can you help me understand this? "Common REST Mistakes: Sessions are irrelevant"
在这里看到很好的讨论:你能帮助我理解这个吗? “常见的REST错误:会话无关紧要”
http://javadialog.blogspot.co.uk/2009/06/common-rest-mistakes.html (point 6)
http://javadialog.blogspot.co.uk/2009/06/common-rest-mistakes.html(第6点)
and
http://www.peej.co.uk/articles/no-sessions.html
Quote from Paul Prescod:
保罗·普雷斯科德的报价:
Sessions are irrelevant.
会话无关紧要。
There should be no need for a client to "login" or "start a connection." HTTP authentication is done automatically on every message. Client applications are consumers of resources, not services. Therefore there is nothing to log in to! Let's say that you are booking a flight on a REST web service. You don't create a new "session" connection to the service. Rather you ask the "itinerary creator object" to create you a new itinerary. You can start filling in the blanks but then get some totally different component elsewhere on the web to fill in some other blanks. There is no session so there is no problem of migrating session state between clients. There is also no issue of "session affinity" in the server (though there are still load balancing issues to continue).
客户端不需要“登录”或“启动连接”。 HTTP验证在每条消息上自动完成。客户端应用程序是资源的消费者,而非服务。因此没有什么可登录的!假设您在REST网络服务上预订航班。您不创建与服务的新“会话”连接。而是你要求“行程创建者对象”为你创建一个新的行程。您可以开始填充空白,然后在网络上的其他地方获得一些完全不同的组件以填充其他一些空白。没有会话,因此在客户端之间迁移会话状态没有问题。服务器中也没有“会话亲和性”问题(尽管仍有负载平衡问题需要继续)。