473,585 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IObjectReferenc e

Hi,
I'm using a IObjectReferenc e 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.G etObjectData( SerializationIn fo info,
StreamingContex t context)
{
info.SetType( typeof(SessionI nfoSerializatio nHelper) );
info.AddValue( "Session", SessionId.ToStr ing() ); //is this correct
}
internal static SessionInfo GetSession( string sessionId )
{
Guid id;
try
{
id = new Guid( sessionId );
}
catch
{
id = Guid.Empty;
}
SessionInfo session;
session = (SessionInfo)_s essions[id];
return session;
}
}

public class SessionInfoSeri alizationHelper : IObjectReferenc e
{
public object GetRealObject(S treamingContext context)
{
// When deserializing this object, return a reference to
// the SessionInfo object instead.
Guid sessionId = ??; // how do I get this???
SessionInfo session = SessionInfo.Get Session( sessionId );
return session;
}
}

Nov 15 '05 #1
1 2159
I believe that your SessionInfoSeri alizationHelper is going to get deserialized
on the other end, so you need that object to implement ISerializable as well.
In that instance, once SessionInfoSeri alizationHelper is deserialized, you'll
have access to the id you are looking for in the SerializationIn fo.

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**********@s pammotel.com> wrote in message
news:eN******** ******@TK2MSFTN GP11.phx.gbl...
Hi,
I'm using a IObjectReferenc e 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.G etObjectData( SerializationIn fo info,
StreamingContex t context)
{
info.SetType( typeof(SessionI nfoSerializatio nHelper) );
info.AddValue( "Session", SessionId.ToStr ing() ); //is this correct
}
internal static SessionInfo GetSession( string sessionId )
{
Guid id;
try
{
id = new Guid( sessionId );
}
catch
{
id = Guid.Empty;
}
SessionInfo session;
session = (SessionInfo)_s essions[id];
return session;
}
}

public class SessionInfoSeri alizationHelper : IObjectReferenc e
{
public object GetRealObject(S treamingContext context)
{
// When deserializing this object, return a reference to
// the SessionInfo object instead.
Guid sessionId = ??; // how do I get this???
SessionInfo session = SessionInfo.Get Session( 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
2212
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 I would greatly in debted to. Serializing the object works fine. When I try to deserialize it, I get the following error: A first chance...
5
24688
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 s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
8
3495
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 to disk multiple times. Now I'm using just basic serialization as described in MSDN. Clearly, I need to stop serializing these parent references, but...
0
1399
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 creatable instances? Please forgive my use of terms. Quasi-signleton is a term I made up and static instances is a little bogus too but I don't...
11
1554
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 contains function SetProp(). When App1 calls it, a property in the DLL is set to "abc". App2 calls a function GetProp(), in the same DLL. GetProp()...
7
5105
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 plain-jane XmlSerializer support. Is there any way this is possible? Chris
0
797
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( "Type1" ); public static readonly MyType Type2 = new MyType( "Type2" );
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.