I'm new to WCF and I've been trying to use the Session state in Web Services, which I managed to get working with a number of articles.
But these articles all fo开发者_开发知识库llow the .net 2.0 approach, as the new WCF Service References do not have a CookieContainer by default.
What is the new school way of using stateful web services?
(Without using backwards approaches, such as code generation with the wsdl.exe tool or the 2.0 "Add Web Service" route.)
One word: DON'T !
Services should be stateless whenever possible - it makes life just that much easier.
If you need to keep state between calls, put it in a persistance container, e.g. a database, and report back the ID under which it can be found for the next call.
Marc
If you really must keep session (really?? Think about it twice - better yet: three times) - then WCF offers per-session calls on certain bindings (protocols).
The basicHttpBinding
which is closest to ASMX webservices for one does not support sessions. You'll need to use wsHttpBinding
for internet-facing apps, or netTcpBinding
for internal intranet-oriented services.
Check out the MSDN docs on using sessions with WCF.
精彩评论