473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

IObjectReference

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;
}
}

Nov 15 '05 #1
1 2146
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" <FB**********@spammotel.com> wrote in message
news:eN**************@TK2MSFTNGP11.phx.gbl...
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;
}
}


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kenneth Baltrinic | last post by:
I am getting the following error when deserializing an object that has a couple of dozen dependant objects in its object graph. Anyone who can suggest where I might begin to look to resolve problem...
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
8
by: Eric Eggermann | last post by:
I'm having a problem with really large file sizes when serializing the classes that describe my little document. There are some circular references which result in the same object getting written...
0
by: Kenneth Baltrinic | last post by:
Is the following code correct for serializing a quasi-single class, that is a class that has a descreet (though more than one, so not a true singleton) number of static instances and no dynamically...
11
by: Charles Law | last post by:
I have just been asked how to share functions and properties between two running applications. For example, I have App1 and App2 both running on the same machine. App1 uses a DLL (perhaps) that...
7
by: chris martin | last post by:
I need to serialize a singelton in my system. It is possible to serialize with BinaryFormatter or SoapFormatter using ISerializable and a helper IObjectReference class. But, what I'm after is...
0
by: Chris Meek | last post by:
I have a type that is something like this public class MyType { private MyType( string pName ) { mName = pName; } private string mName; public static readonly MyType Type1 = new MyType(...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.