Before sending the data to the client, we can compress the stream using the C1.Zip library (the desktop version included with ComponentOne Studio, not the Silverlight version). To do this, we modify the MasterDetailWeb project by adding a reference to the C1.Zip library, then changing the GetData method in the DataService.asmx.cs Web service as follows:
C# |
Copy Code
|
---|---|
[WebMethod] public byte[] GetData(string tables) { // Create DataSet with connection string var ds = GetDataSet(); // Load data into DataSet ds.Fill(tables.Split(',')); // Persist to stream var ms = new MemoryStream(); using (var sw = new C1.C1Zip.C1ZStreamWriter(ms)) ds.WriteXml(sw, XmlWriteMode.WriteSchema); //ds.WriteXml(ms, XmlWriteMode.WriteSchema); // Return stream data return ms.ToArray(); } |
This small change is all that's required to compress the data on the server before sending it to the client. Instead of persisting the DataSet directly to the stream, we are now persisting it through a C1ZStreamWriter that compresses the data before writing it to the stream. Because the data is encoded as XML, compression rates will be very good.