Connecting Tech Pros Worldwide Forums | Help | Site Map

IObjectReference

Greg Bacchus
Guest
 
Posts: n/a
#1: Nov 15 '05
Hi,
I'm using a IObjectReference object to help deserialize a SessionInfo class.
But with a catch:
What I want to do is have it so that a SessionInfo Id is serialized and in
deserialization the ObjectReference uses this Id to select the correct
SessionInfo to return.

So, each SessionInfo class registers itself with a static list in its
constructor, and there is a static method for returning a session given a
session Id.

What I need to know is how to get the session Id that was stored during
serialization when I'm deserializing.

Can anyone help me? I've included some code snippets below to hopefully help
you understand what I'm talking about.
Thanks
Greg


public class SessionInfo : ISerializable
{
private Guid _sessionId;
public Guid SessionId { get { return _sessionId; } }
private static Hashtable _sessions = new Hashtable();
public SessionInfo( IDataProvider dataProvider )
{
_sessionId = Guid.NewGuid();
_sessions[SessionId] = this;
}
void ISerializable.GetObjectData( SerializationInfo info,
StreamingContext context)
{
info.SetType( typeof(SessionInfoSerializationHelper) );
info.AddValue( "Session", SessionId.ToString() ); //is this correct
}
internal static SessionInfo GetSession( string sessionId )
{
Guid id;
try
{
id = new Guid( sessionId );
}
catch
{
id = Guid.Empty;
}
SessionInfo session;
session = (SessionInfo)_sessions[id];
return session;
}
}

public class SessionInfoSerializationHelper : IObjectReference
{
public object GetRealObject(StreamingContext context)
{
// When deserializing this object, return a reference to
// the SessionInfo object instead.
Guid sessionId = ??; // how do I get this???
SessionInfo session = SessionInfo.GetSession( sessionId );
return session;
}
}






Justin Rogers
Guest
 
Posts: n/a
#2: Nov 15 '05

re: IObjectReference


I believe that your SessionInfoSerializationHelper is going to get deserialized
on the other end, so you need that object to implement ISerializable as well.
In that instance, once SessionInfoSerializationHelper is deserialized, you'll
have access to the id you are looking for in the SerializationInfo.

This is really odd stuff and is mainly used for remoting objects by reference
and implementing proxies. Across what boundaries are your objects being
serialized?

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Greg Bacchus" <FBRAJGOPLBRF@spammotel.com> wrote in message
news:eNuem6G9DHA.2316@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hi,
> I'm using a IObjectReference object to help deserialize a SessionInfo class.
> But with a catch:
> What I want to do is have it so that a SessionInfo Id is serialized and in
> deserialization the ObjectReference uses this Id to select the correct
> SessionInfo to return.
>
> So, each SessionInfo class registers itself with a static list in its
> constructor, and there is a static method for returning a session given a
> session Id.
>
> What I need to know is how to get the session Id that was stored during
> serialization when I'm deserializing.
>
> Can anyone help me? I've included some code snippets below to hopefully help
> you understand what I'm talking about.
> Thanks
> Greg
>
>
> public class SessionInfo : ISerializable
> {
> private Guid _sessionId;
> public Guid SessionId { get { return _sessionId; } }
> private static Hashtable _sessions = new Hashtable();
> public SessionInfo( IDataProvider dataProvider )
> {
> _sessionId = Guid.NewGuid();
> _sessions[SessionId] = this;
> }
> void ISerializable.GetObjectData( SerializationInfo info,
> StreamingContext context)
> {
> info.SetType( typeof(SessionInfoSerializationHelper) );
> info.AddValue( "Session", SessionId.ToString() ); //is this correct
> }
> internal static SessionInfo GetSession( string sessionId )
> {
> Guid id;
> try
> {
> id = new Guid( sessionId );
> }
> catch
> {
> id = Guid.Empty;
> }
> SessionInfo session;
> session = (SessionInfo)_sessions[id];
> return session;
> }
> }
>
> public class SessionInfoSerializationHelper : IObjectReference
> {
> public object GetRealObject(StreamingContext context)
> {
> // When deserializing this object, return a reference to
> // the SessionInfo object instead.
> Guid sessionId = ??; // how do I get this???
> SessionInfo session = SessionInfo.GetSession( sessionId );
> return session;
> }
> }
>
>
>
>
>[/color]


Closed Thread