When you pass a System.Data.DataSet
object between processes, .NET Framework Remoting is used to serialize, to transport, and to deserialize the DataSet
class. If you pass a DataSet
class back from a .NET Web Service, internally the Microsoft .NET Framework System.Xml.Serialization.XMLSerializer
class is used to serialize the DataSet
data back to the client. If you pass a DataSet
back from a managed object that is hosted in COM+, the BinaryFormatter
class is used by .NET Framework Remoting. Regardless of the remoting mechanism that is used by the .NET Framework, the DataSet
class always converts the internal data to XML when serializing the data.
class that is included with the Microsoft .NET Framework 1.0 and with the .NET Framework 1.1 works efficiently for serializing small amounts of data (hundreds of rows) in the DataSet
over .NET Framework Remoting. The serialization mechanism is inefficient with a larger DataSet
(thousands of rows) and incurs large transient (short lived) memory allocations. These memory allocations reduce application scalability.Note
A transient memory allocation is a short-lived memory allocation that occurs during the processing of some sections of code. Therefore, during the serialization, during the remoting, and during the deserialization of a DataSet
class, various managed objects are allocated and deallocated internally by .NET Framework Remoting to process the remoting request. Allocating and deallocating larger and larger managed objects puts additional pressure on the .NET memory management system and reduces overall scalability. For example, an application that has many in-flight method invocations that generate large transient memory allocations can run out of memory before completing all the method calls.
You can greatly improve serialization and remoting performance for larger DataSets
by using a correctly designed surrogate type or serialization wrapper classes. For more information about using a surrogate mechanism or a wrapper mechanism (or both) with the .NET Framework DataSet
class, visit the following Microsoft Developer Network (MSDN) Web site:
However, this article does not provide a complete sample of how to implement a DataSet
surrogate type or a serialization wrapper class.
This article contains a sample serialization wrapper class that is optimized to more efficiently serialize and deserialize larger DataSets
. The class significantly reduces transient memory allocations versus remoting a typical DataSet
. Large reductions in the transient memory allocations also improve remoting end-to-end time and improve scalability when using a larger DataSet
The sample provides a serialization wrapper class that is named DataSetSurrogate
. The DataSetSurrogate
class is used as a wrapper class for any DataSet
that you want to remote. The server component passes the DataSet
that you want to the DataSetSurrogate
constructor and then passes the DataSetSurrogate
class back to the client. On the client side, the DataSetSurrogate.ConvertToDataSet
method is used to extract the DataSet
from the DataSetSurrogate
class is marked Serializable
and all the fields in the DataSetSurrogate
class are also serializable classes. Therefore, when you remote the DataSetSurrogate
object, the remoting infrastructure automatically serializes and deserializes the DataSetSurrogate
object and all its fields. The key serialization advantage of the DataSetSurrogate
class over the DataSet
class is that the DataSetSurrogate
class serializes the data in a binary format. Serializing by using a binary format is much more efficient both in memory and CPU than the existing DataSet
XML serialization format.Note
To maximize the performance benefit of this serialization wrapper class, use the .NET Framework System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
class when remoting. Remoting by using the .NET Framework System.Runtime.Serialization.Formatters.Soap.SoapFormatter
class is not as efficient when you use the DataSetSurrogate
The following file is available for download from the Microsoft Download Center:Download the SurrogateSample.exe package now.
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
Access the Sample Files
Save the SurrogateSample.exe file to drive C on your computer. From there you can extract the folder structure. There is a readme file in each folder that contains additional instructions.