Hello
I need to send data (a whole class) from a Sever to a Client.
I convert this class to a binary array using Binary Serialization:
public byte[] ToBytes(){
try{
IFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream,this);
byte[] Bytes = new byte[stream.Length];
stream.Seek(0,System.IO.SeekOrigin.Begin);
stream.Read(Bytes,0,(int)stream.Length);
return Bytes;
}catch{
return null;
}
}
On the client side I recive the array of bytes and Deserialize them using:
public static CQuery FromBytes(byte[] Bytes){
try{
IFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(Bytes.Length);
stream.Write(Bytes,0,(int)Bytes.Length);
stream.Seek(0,System.IO.SeekOrigin.Begin);
return (CQuery)formatter.Deserialize(stream);
}
catch{
return null;
}
}
My problem is that the client needs to know the Class type (casting after
deserialize) and the only way to do this is have the *same* DLL contating the
class on both server & client.
How can I do Serialization without having to supply the DLL but rather
define the class (exactly the same mathods) in the same way it is defined on
the server side.
Gilad.