IObjectReference

  • Thread starter Thread starter Greg Bacchus
  • Start date Start date
G

Greg Bacchus

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;
}
}
 
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?
 
Back
Top