Serializing a dataset

  • Thread starter Thread starter John J. Hughes II
  • Start date Start date
J

John J. Hughes II

I am serializing a dataset and sending it across a slow socket connection
using the following code. I know I can send binary data across a socket but
when I serialize the dataset it ends up being text and very large. I am
thinking about zipping it but was wondering if maybe there was a better way?

System.Runtime.Serialization.IFormatter f = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream ms1 = new System.IO.MemoryStream();
f.Serialize(ms1, DataArg);
this.socket.Send(ms1.GetBuffer());

Regards,
John
 
You serialize the dataset as XML, then zip it. See the zip library at

http://www.icsharpcode.com

I've used, it's great. As you may already know, you can serialize a dataset
to a XML with the function WriteXML(). The zip library can then read the
file and compress it.

The only quirk I found with the zip lib is that is doesn't
compress/decompress MemoryStreams, only FileStreams.
 
Kevin,

Well our company does not want our project under the GPL and if I include
that code then I have to if I understand correctly.

As a side note I have found serializing the data makes a smaller footprint
then writing to XML which really makes no sense but that be the case. This
might change if the parameters for the XML write were changed, I did not
look into it that far.

System.Runtime.Serialization.IFormatter f = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream ms1 = new System.IO.MemoryStream();
f.Serialize(ms1, DataArg);

System.IO.MemoryStream ms = new System.IO.MemoryStream();
DataArg.dsData.WriteXml(ms);

ms1.Length 23069716
ms.Length 24932130

Regards,
John
 
One caveat with serializing the dataset is that you remove
compatibility with anything other than a .NET based client/server...
and changing the data format can be annoying. It's usually much better
to save as xml and zip or compress the data somehow.
 
Johnny,

I can see you point. Currently I am talking to myself so to say ( writing
both ends ) so don't really consider it a problem but will keep that in
mind.

Regards,
John
 
Back
Top