[Mono-list] advanced .Net remoting: serialization formatter
Urs Muff
umuff@quark.com
Tue, 25 Feb 2003 12:34:19 -0700
I have one other question:
Is there a way of installing standard serialization translation formatter to
a give channel?
What I want is the following:
System.Drawing.Image for instance is derived from MashalByRefObject, but
when a proxy version of an image is used (like Save(stream,ImageFormat.Jpeg)
or similar) the serialization fails. Image is not marked as serializable,
but it would be very easy to do:
public static byte[] ImageToStream(Image image)
{
MemoryStream s = new MemoryStream();
image.Save(s,ImageFormat.Jpeg);
s.Close();
return s.GetBuffer();
}
public static Image StreamToImage(byte[] image)
{
return Image.FromStream(new MemoryStream(image));
}
But the problem is that I might have a structure like:
class ServerSide : MarshalByRefObject
{
public void Method(Image image) { ... }
}
When I call from the client:
ServerSide s = Activation.GetObject(...) as ServerSide;
s.Method(Image.FromFile("/tmp/test.gif"));
I would like the formatter to kick in, and automatically serialize the image
to a byte[] and de-serialize back. Is that possible on a channel formatter
level, so that I don't have to change the method signature?
This applied for other objects like object[], Hashtable, and others that
could be serialized very easily in general purpose code.
- URS C. MUFF