Asp.net 会话似乎不适用于 WCF WebHttpBinding
我们正在做一个 WCF REST json 服务 (WebHttpBinding)。由于纯 WCF 会话不适用于这种绑定,因此我们使用 asp.net 会话。所以我们设置:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
在我们的 web.config 中,并且:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
在我们的服务实现之上。 我们有几个服务方法,例如:
public void OpenSession(string userName)
public void GetSomething(int somethingId)
public void CloseSession()
然后我们在每个方法中测试 HttpContext 的 sessionId。
HttpContext.Current.Session.SessionID
问题是:它总是在变化。 如果我在网络浏览器中调用 OpenSession?userName='toto',并在 GetSomething?somethingId=1234 后调用另一个调用,则会话 ID 将会更改。
wcf 似乎没有很好地处理 cookie。如果我在 fiddler 中调用 OpenSession 方法,在 http 标头中,服务不会返回“Set-Cookie”。
We're doing a WCF REST json service (WebHttpBinding). Since pure WCF session doesn't work with this kind of binding, we are using asp.net session. So we set:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
In our web.config, and :
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
On top of our service implementation.
We have several service methods such as:
public void OpenSession(string userName)
public void GetSomething(int somethingId)
public void CloseSession()
Then we test the sessionId of the HttpContext in each method.
HttpContext.Current.Session.SessionID
Problem is: it's always changing.
If I make a call to OpenSession?userName='toto' in my web browser, and another one right after to GetSomething?somethingId=1234, the session id will change.
It seems that the cookies aren't well handled by wcf. If I call the OpenSession method in fiddler, in the http headers, there're no 'Set-Cookie' returned by the service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现:
就在这篇文章里。检查它是否对您有用: http:// blogs.msdn.com/b/wenlong/archive/2006/01/23/516041.aspx
I found that :
It's in this article. Checki if it will be usefull for you : http://blogs.msdn.com/b/wenlong/archive/2006/01/23/516041.aspx