prompt please how can I use session in self hosted WCF? I need to implement ASP.NET like sessions (client identification and possibly data sharing). Is there any native way to do so in WCF or I have to implement this behavior manually (sending some unique value with each request and storing them in some sessionID store)? Thanks in advance. P.S. Sorry for poor English.
Asked
Active
Viewed 787 times
1 Answers
2
You can have sessions in self-hosted WCF, but you'll need to use a binding which has session support. WSHttpBinding, NetTcpBinding and NetNamedPipeBindings all support sessions, as well as other combination of binding elements in custom bindings. You won't be able to use sessions in a BasicHttpBinding, for example, since you won't have the underlying ASP.NET session object it can take advantage of.

carlosfigueira
- 85,035
- 14
- 131
- 171
-
Thank you for a response Carlos, but I am not sure that it is exactly what I need. As I can understand from various msdn* articles, WCF session is something that works during one proxy object calls, so if I create proxy object for each call I'll lose a session. Moreover, it is a possible that I'll have to share session between 2 or more endpoints (i.e. proxies). So, I need some unique ID that identifies a client for every call does not matter what proxy object is used. – Artyom May 31 '11 at 07:48
-
I see, so you need a session spawning multiple clients. In this case it's still posible, but you'll have to essentially manage the session yourself. On the server side you can use some object such as a MemoryCache (http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx) to store the session information, and also use some inspector (IDispatchMessageInspector) to write an unique id to all outgoing messages (depending on the "session" to which the call belongs), and map the session to the incoming requests which should have that id as either a SOAP or a HTTP header. – carlosfigueira May 31 '11 at 15:35