简体   繁体   中英

Stateful WCF Web Service

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 follow 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, eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM