tags:

views:

61

answers:

2

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?

+1  A: 

Yes you should use session, it's much faster than making a http request

Stephen lacy
Of the choices given, session is better - the key however is that you almost certainly don't want to re-make the http request, I'd suggest that whether you then use session or another mechanism (e.g. cache) to persist the object is a subject for further discussion.
Murph
Yes if he is using a state server or sql server for session then it would have to serialise the object again so that would take up time. Also when you store in session app recycling causes the session to disappear. The cache exists outside of the appdomain.
Stephen lacy
+1  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

marc_s
+1. Yeap- I agree.
RichardOD