How to: Chunk Serialized Data
Two issues that occur when sending large data sets in Web service messages are:
A large working set (memory) due to buffering by the serialization engine.
Inordinate bandwidth consumption due to 33 percent inflation after Base64 encoding.
To implement server-side chunking
On the server machine, the Web method must turn off ASP.NET buffering and return a type that implements IXmlSerializable.
The type that implements IXmlSerializable chunks the data in the WriteXml method.
To implement client-side processing
Alter the Web method on the client proxy to return the type that implements IXmlSerializable. You can use a SchemaImporterExtension to do this automatically, but this is not shown here.
Implement the ReadXml method to read the chunked data stream and write the bytes to disk. This implementation also raises progress events that can be used by a graphic control, such as a progress bar.
The following code example shows the Web method on the client that turns off ASP.NET buffering. It also shows the client-side implementation of the IXmlSerializable interface that chunks the data in the WriteXml method.
Compiling the Code
Copyright © 2007 by Microsoft Corporation. All rights reserved.