473,387 Members | 1,542 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,387 software developers and data experts.

Binary Serialization over the net

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.
Nov 17 '05 #1
1 1594
Hi,
The client NEEDS the dll no matter what, in the DLL is where the code of
the class is declared. Otherwise how the client could invoke methods or
properties of the instance?

Just for sake of clarity, remember that you send an INSTANCE of a class, not
a class (AKA type)

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gilad Kapelushnik" <Gi**************@discussions.microsoft.com> wrote in
message news:24**********************************@microsof t.com...
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.

Nov 17 '05 #2

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

Similar topics

4
by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
2
by: Dave Veeneman | last post by:
I'm working on a project where I have to persist data to a file, rather than to a database. Basically, I need to save the state of several classes, each of which will have a couple of dozen...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
7
by: schoenfeld1 | last post by:
I've implemented IPC between two applications using named pipes and binary serialization, but have noticed that the binary formatter is rather slow. It seems that the binary formatter reflects...
15
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with...
0
by: Vince Filby | last post by:
Hi, We are working with distributing Lucene.net. We have Master Index Server which takes responsibility of distributing the index searching to multiple Index Servers by calling the remote...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
1
by: sandeepbhutani304 | last post by:
have 2 projects communicating each other with .NET remoting. But when I am trying to call these functions I am getting the error: The input stream is not a valid binary format. The starting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...

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.