WCF Web Service Stateful

I am new to WCF and I tried to use session state in web services that I managed to work with article number .

But all of these articles follow the .net 2.0 approach, since new WCF service links do not contain a CookieContainer by default.

What is the new school way to use stateful web services?

(Without using backward approaches, such as generating code using the wsdl.exe tool or the 2.0 Add Web Service route.)

+4
source share
1 answer

One word: NOT !

Services should be stateless whenever possible - this makes life easier.

If you need to maintain state between calls, put it in a resistance container, for example. database and provide an identifier under which it can be found for the next call.

Mark


If you really have to keep the session ( really? ), Think about it twice - even better: three times) - then WCF offers session calls to specific bindings (protocols).

basicHttpBinding , which is closest to ASMX web services for one, does not support sessions. You need to use wsHttpBinding for Internet oriented applications, or netTcpBinding for intranet oriented internal services.

Read MSDN docs when using sessions with WCF.

+6
source

All Articles