开发者

WCF Session Management

I am new to WCF and trying to accomplish a few things in terms of session management:

  1. I would like to get an event on the server when a new session is opened/created.

  2. I would like the ability to either close all open ses开发者_StackOverflowsions, or get a list of open sessions and close specific ones (on the server, of course).

How would I go about doing this? Google has been surprisingly unhelpful...


The answer is going to be a lot of "it depends". Some of the bindings are not session aware. Something like BasicHttpBinding for example doesn't do sessions on its own, but if you enable ASP.net compatability mode you can get ASP.net's session management to work. You will then be able to use Session_Start and Session_End in global.asax to do what you want when sessions are opening or closing.

You should look at the binding you're using and see if it has some kind of session support built in, because some of them do.

If you're doing authentication, you could also imitate a session management system by mapping requests to authenticated users and storing the session record in the database.

I will say that in any case I'm not sure what "closing" a session is going to get you. Unless you're also locking the user out somehow, the next request will just immediately start a new session if the previous one was ended. Maybe if you explain what goal you want to accomplish (and why) we can be of further help.


I agree with Tridus's answer on this. You can use Session with WCF services by enabling ASP.NET Compatibility Mode.

Check http://msdn.microsoft.com/en-us/library/aa702542.aspx for an initial reading. Keep in mind - Services are supposed to be stateless by principle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜