Oh, now this is interesting: If I open up the binary file created by the binary serialization of a DataSet in notepad, the contents of the file are XML! That's really odd; I know for a fact that other types don't produce XML during binary serialization. No wonder the size of the uncompressed binary is so close to the size of the XML file.
> -----Original Message----- > From: Joel Mueller [mailto:[EMAIL PROTECTED]] > Sent: Thursday, May 02, 2002 2:42 PM > To: 'dotnet discussion' > Subject: RE: [DOTNET] HTTP Compression of XML WebServices > > > Here's an example for you that does binary serialization of a > DataSet, compressing the serialized stream on the fly. On my > system, the uncompressed XML from the DataSet is 31,253 > bytes, the uncompressed binary version of the dataset is > 30,804 bytes, and the compressed binary version is 3,841 bytes. > > using System; > using System.IO; > using System.Data; > using System.Data.SqlClient; > using System.Runtime.Serialization; > using System.Runtime.Serialization.Formatters.Binary; > > using NZlib.GZip; > > class Class1 > { > [STAThread] > static void Main(string[] args) > { > SqlConnection myConnection = new > SqlConnection("server=localhost;trusted_connection=yes;databas > e=Northwind"); > SqlDataAdapter myAdapter = new > SqlDataAdapter("SELECT * FROM Products", myConnection); > > DataSet ds = new DataSet(); > myAdapter.Fill(ds); > > Console.WriteLine("DataSet rows: {0}, cols: > {1}", ds.Tables[0].Rows.Count, ds.Tables[0].Columns.Count); > > StreamWriter xmlOut = File.CreateText("products.xml"); > xmlOut.Write(ds.GetXml()); > xmlOut.Close(); > > Console.WriteLine("XML file size: {0:n} bytes", > new FileInfo("products.xml").Length); > > IFormatter formatter = new BinaryFormatter(); > Stream output = new > GZipOutputStream(File.Create("products.bin.gz")); > formatter.Serialize(output, ds); > output.Close(); > > Console.WriteLine("Compressed binary file size: > {0:n} bytes", new FileInfo("products.bin.gz").Length); > } > } > > > > > -----Original Message----- > > From: dotnet discussion [mailto:[EMAIL PROTECTED]] > > On Behalf Of franklin gray > > Sent: Thursday, May 02, 2002 2:02 PM > > To: [EMAIL PROTECTED] > > Subject: Re: [DOTNET] HTTP Compression of XML WebServices > > > > > > oh....well that makes things a little different. I guess I > > should have asked about that sooner:-( Thanks for the info. > > It might come in very handy. I am still playing with the > > binary serializtion of a Dataset because I have noticed that > > for large datasets, it can take a while to create the dataset > > from xml. Does anybody have an example of a binary > > serialization of a dataset avaiable? > > > > -----Original Message----- > > From: Marsh, Drew [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, May 02, 2002 1:44 PM > > To: [EMAIL PROTECTED] > > Subject: Re: [DOTNET] HTTP Compression of XML WebServices > > > > > > franklin gray [mailto:[EMAIL PROTECTED]] wrote: > > > > > by doing this binary serialization of a dataset, would it > > be the same > > > dataset? I too do it the way Robert does, by getting the xml and > > > re-creating it on the client after decryption and > > decompression. The > > > problem I have is that I loose the row state. IE...If > > change two rows > > > on the client, send the ds xml back to the server, then > > recreate the > > > DS on the server, I will not have two rows in the > Getchanges method, > > > I will have a row for every row as an addded row. Would Binary > > > serialization would solve this problem? > > > > Are you using WriteXml or GetXml? If you need to maintain > > rowstate you need to use WriteXml with XmlWriteMode.DiffGram. > > If you want to only serialize the *changes*, then you should > > call GetChanges and WriteXml the resulting DataSet as a DiffGram. > > > > HTH, > > Drew > > > > You can read messages from the DOTNET archive, unsubscribe > > from DOTNET, or subscribe to other DevelopMentor lists at > > http://discuss.develop.com. > > > > You can read messages from the > > DOTNET archive, unsubscribe from DOTNET, or subscribe to > > other DevelopMentor lists at http://discuss.develop.com. > > > > > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.