unexpected behaviour of object stored in web service Session
Posted
by draconis
on Stack Overflow
See other posts from Stack Overflow
or by draconis
Published on 2010-05-07T15:22:18Z
Indexed on
2010/05/07
15:38 UTC
Read the original article
Hit count: 220
Hi. I'm using Session variables inside a web service to maintain state between successive method calls by an external application called QBWC. I set this up by decorating my web service methods with this attribute:
[WebMethod(EnableSession = true)]
I'm using the Session variable to store an instance of a custom object called QueueManager. The QueueManager has a property called ChangeQueue which looks like this:
[Serializable]
public class QueueManager
{
...
public Queue<QBChange> ChangeQueue { get; set; }
...
where QBChange is a custom business object belonging to my web service.
Now, every time I get a call to a method in my web service, I use this code to retrieve my QueueManager object and access my queue:
QueueManager qm = (QueueManager)Session[ticket];
then I remove an object from the queue, using
qm.dequeue()
and then I save the modified query manager object (modified because it contains one less object in the queue) back to the Session variable, like so:
Session[ticket] = qm;
ready for the next web service method call using the same ticket.
Now here's the thing: if I comment out this last line
//Session[ticket] = qm;
, then the web service behaves exactly the same way, reducing the size of the queue between method calls. Now why is that?
The web service seems to be updating a class contained in serialized form in a Session variable without being asked to. Why would it do that? When I deserialize my Queuemanager object, does the qm variable hold a reference to the serialized object inside the Session[ticket] variable?? This seems very unlikely.
© Stack Overflow or respective owner