HighTechTalks DotNet Forums  

Store Asyncresult to session with sessionState mode = "SQLServer"

Dotnet Framework (Remoting) microsoft.public.dotnet.framework.remoting


Discuss Store Asyncresult to session with sessionState mode = "SQLServer" in the Dotnet Framework (Remoting) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
sean.swords@gmail.com
 
Posts: n/a

Default Store Asyncresult to session with sessionState mode = "SQLServer" - 10-06-2006 , 09:38 AM






Hi there,
I was previously able to store my AsyncResult to the Session with the
sessionstate mode="InProc" but now I get:

System.Web.HttpException: Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not
permitted when session state mode is 'StateServer' or 'SQLServer'.

Is there any way to serialize the AsyncResult or is there some other
workaround? It seems ridiculous that simply changing the mode of
session storage should have such a radical effect on the design of an
application.
Thanks,
Sean.


Reply With Quote
  #2  
Old   
Chris Taylor
 
Posts: n/a

Default Re: Store Asyncresult to session with sessionState mode = "SQLServer" - 10-06-2006 , 01:16 PM






Hi,

Storing session in a memory cache within the same process and remotely in
the memory of another process is very different. InProc does not require
serialization therefore any references can be stored while session state
stored out of process has to be serialized for transmission.

With the teams I work with I usually recommend that they develop with using
the ASP.NET state service on the local machine. That way they do not get any
surprises when they need to deploy to a web farm environment.

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
<sean.swords (AT) gmail (DOT) com> wrote

Quote:
Hi there,
I was previously able to store my AsyncResult to the Session with the
sessionstate mode="InProc" but now I get:

System.Web.HttpException: Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not
permitted when session state mode is 'StateServer' or 'SQLServer'.

Is there any way to serialize the AsyncResult or is there some other
workaround? It seems ridiculous that simply changing the mode of
session storage should have such a radical effect on the design of an
application.
Thanks,
Sean.




Reply With Quote
  #3  
Old   
sean.swords@gmail.com
 
Posts: n/a

Default Re: Store Asyncresult to session with sessionState mode = "SQLServer" - 10-09-2006 , 04:41 AM



Cheers Chris, and so can the AsyncResult object be serialized? How
should I go about this?
Thanks,
Sean

Chris Taylor wrote:
Quote:
Hi,

Storing session in a memory cache within the same process and remotely in
the memory of another process is very different. InProc does not require
serialization therefore any references can be stored while session state
stored out of process has to be serialized for transmission.

With the teams I work with I usually recommend that they develop with using
the ASP.NET state service on the local machine. That way they do not get any
surprises when they need to deploy to a web farm environment.

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
sean.swords (AT) gmail (DOT) com> wrote in message
news:1160141924.921162.152750 (AT) i42g2000cwa (DOT) googlegroups.com...
Hi there,
I was previously able to store my AsyncResult to the Session with the
sessionstate mode="InProc" but now I get:

System.Web.HttpException: Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not
permitted when session state mode is 'StateServer' or 'SQLServer'.

Is there any way to serialize the AsyncResult or is there some other
workaround? It seems ridiculous that simply changing the mode of
session storage should have such a radical effect on the design of an
application.
Thanks,
Sean.



Reply With Quote
  #4  
Old   
Günter Prossliner
 
Posts: n/a

Default Re: Store Asyncresult to session with sessionState mode = "SQLServer" - 10-09-2006 , 07:43 AM



Hi!

Quote:
and so can the AsyncResult object be serialized?
No. You have to find another solution. You can keep the AsyncResults in a
static collection witch is always a in-memory structure:

class AsyncResultManager {

static Dictionary<string, IAsyncResult> _dic = new ...;

public IAsyncResult Get(string key){
return _dic[key];
}

public void Set(string key, IAsyncResult ar){
_dic[key] = ar;
}

}

Be be arware that every server within a web-farm maintains its own List.
Completing asyncron calls from another server that have begun it is not
supported (by every implementation I' aware of) anyway.


GP




Reply With Quote
  #5  
Old   
sean.swords@gmail.com
 
Posts: n/a

Default Re: Store Asyncresult to session with sessionState mode = "SQLServer" - 10-09-2006 , 10:57 AM



Thanks for the tips guys but I opted for a considerably simpler option
that seems to work perfectly. I wanted to store the result in the
session so I could maintain separate asynchronous operations for each
logged in user. The cache can achieve the same functionality like so
(VB):
Cache("result" + Session.SessionID) = ar
Cheers

Günter Prossliner wrote:
Quote:
Hi!

and so can the AsyncResult object be serialized?

No. You have to find another solution. You can keep the AsyncResults in a
static collection witch is always a in-memory structure:

class AsyncResultManager {

static Dictionary<string, IAsyncResult> _dic = new ...;

public IAsyncResult Get(string key){
return _dic[key];
}

public void Set(string key, IAsyncResult ar){
_dic[key] = ar;
}

}

Be be arware that every server within a web-farm maintains its own List.
Completing asyncron calls from another server that have begun it is not
supported (by every implementation I' aware of) anyway.


GP


Reply With Quote
  #6  
Old   
Günter Prossliner
 
Posts: n/a

Default Re: Store Asyncresult to session with sessionState mode = "SQLServer" - 10-09-2006 , 11:58 AM



Hi!

Quote:
but I opted for a considerably simpler option
that seems to work perfectly. I wanted to store the result in the
session so I could maintain separate asynchronous operations for each
logged in user.

Cache("result" + Session.SessionID) = ar
Ok. But be aware that:

* A new Session may get the same SessionID again (because when a Session
ends the cookie remains within the Browsers memory). So it is no bad idea to
clear the value from the cache within Session_Start

* Cache items may get removed from the Cache automaticly. There are memory -
limits for the cache. At least you should insert the objects with the
CacheItemPriority.NotRemovable.

I would still recommend that you use static Fields instead of the Cache to
avoid the unnessersary overhead of the Cache Object because you do not need
the things that the Cache Object offers you (like expiration, dependecies
and auto-remove), you just want to store a Object-Reference within memory.

You can use the SessionID as a key within the helper - property:

static class AsyncResultManager {

public static Dictionary<string, IAsyncResult> _dic = new ...();

public static IAsyncResult UserAsyncResult {
get{
return _dic[HttpContext.Current.Session.SessionID];
}

set{
_dic[HttpCOntext.Current.Session.SessionID] = value;
}

}

}



GP




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.