Q:

Session vs Call to web service

I have a web application which calls WCF service to get an object.
I requre the object after post back.
I am using session to store the object for later use.
The use of session comes with an associated cost.
The other option i have is to call the service again to get the object.
I am not sure what is the good way of doing this?
Anyone any idea on this?

A:

I would argue against using sessions with WCF. Sessions tend to bring along a slew of problems that you do not have with per-call mechanism: sessions can abort (network down), sessions can time out if you don't do anything for a set period of time and so forth - and you'll have to be ready and able to handle all those scenarios one way or another.
Sessions seems like a really good idea at first - but they tend to get messy and cumbersome later on. If ever possible, try to avoid sessions - the per-call mechanism in WCF is probably the recommend best practice, unless you really really REALLY have to have sessions (like security or reliable sessions etc.).
Having your persistant objects stored in a store that is designed to do that (like SQL Server) is the much better, and ultimately much easier choice. Yes, you might have to request the object a second time once in a while - so what? Ultimately, those few milliseconds are gonig to hurt a lot less, compared to having to deal with all the sessions "messiness" in terms of development time and handling special cases....
Marc

