Export (0) Print
Expand All

How to: Chunk Serialized Data

Two issues that occur when sending large data sets in Web service messages are:

  1. A large working set (memory) due to buffering by the serialization engine.

  2. Inordinate bandwidth consumption due to 33 percent inflation after Base64 encoding.

To solve these problems, implement the IXmlSerializable interface to control the serialization and deserialization. Specifically, implement the WriteXml and ReadXml methods to chunk the data.

To implement server-side chunking

  1. On the server machine, the Web method must turn off ASP.NET buffering and return a type that implements IXmlSerializable.

  2. The type that implements IXmlSerializable chunks the data in the WriteXml method.

To implement client-side processing

  1. 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.

  2. 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.

Example

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

See Also



Copyright © 2007 by Microsoft Corporation. All rights reserved.

Community Additions

Show:
© 2014 Microsoft