REST WCF 服务和会话在 ASP.NET 中
如果可以的话请帮忙。
我一直在尝试从 WCF REST 服务中访问 asp.net 应用程序的当前会话对象。
根本没有成功。从服务访问的会话对象与 aspx 页面中的会话对象不同。
所以,这是我的问题:是否可以通过 HttpContext.Current.Session 访问 REST WCF 服务中的当前会话?
代码有以下几点:
[AspNetCompatibilityRequirements
(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)] // I have also tried Required
public class DataService : IDataService
在web.config中:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ClosedRoom.DataServiceBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" >
<baseAddressPrefixFilters>
<add prefix="http://localhost:63399"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service name="ClosedRoom.DataService">
<endpoint address="" behaviorConfiguration="ClosedRoom.DataServiceBehavior"
binding="webHttpBinding" contract="ClosedRoom.IDataService" />
</service>
</services>
</system.serviceModel>
谢谢,
Please help if you can.
I have been trying to access the current session object of an asp.net application from within a WCF REST service.
There has been no success at all. the session object accessed from the service is not the same one in the aspx pages.
So, here is my question: Is it possible to access the current session in a REST WCF service through HttpContext.Current.Session ?
The code has the following points:
[AspNetCompatibilityRequirements
(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)] // I have also tried Required
public class DataService : IDataService
in web.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ClosedRoom.DataServiceBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" >
<baseAddressPrefixFilters>
<add prefix="http://localhost:63399"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service name="ClosedRoom.DataService">
<endpoint address="" behaviorConfiguration="ClosedRoom.DataServiceBehavior"
binding="webHttpBinding" contract="ClosedRoom.IDataService" />
</service>
</services>
</system.serviceModel>
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了重新恢复会话,您需要提供密钥。在普通的 ASP.NET 应用程序中,该密钥由用户通过 cookie 或 url 参数提供。
您打算如何从 REST 客户端获取该密钥?这些客户端在身份验证后最初如何获取该密钥?他们把钥匙存放在哪里?
这就是为什么大多数基于 REST 的服务都采用 API 访问密钥和另一个密钥来签署每个请求。
恕我直言,会话与基于 REST 的设计无关。
In order for a session to be rehidrated, you need to supply a key. In a normal asp.net application that key is supplied by user either via cookie or url parameter.
How are you planning to acquire that key from the REST client? How those clients get that key initially after the authentication? Where they store the key?
This is why most of the REST based services take a api access key and also another key to sign every request.
IMHO sessions are irrelevant in REST based designs.
我知道这个问题很久以前就被问到了,但这可以通过在 ASP.NET 应用程序中托管 WCF Restful 服务来实现,然后在服务类的顶部添加以下属性:
这可以实现许多功能,包括:
请参阅此处了解详细信息:AspNetCompatibilityRequirements 的真正含义是什么?
I know this question was asked a long time ago but this can be achieved by hosting the wcf restful service within an asp.net application and then on the top of your service class add the following attribute:
This enables many things including:
See here for more info: What does AspNetCompatibilityRequirements really mean?