tags:

views:

40

answers:

1

Hi,

I have an a client that executes some sql and gets the results in the form of a DataSet. This DataSet gets put into an object called "ExecutionResults" where a property called "Data" of type Object holds this DataSet. I wish to send this "ExecutionResults" object across the wire by calling a WCF web service method "SavePackageExecutionResults(ExecutionResults results)" and have service to deserialize the "Data" property of ExecutionResults into a DataSet.

I am creating both the client and the service. There are two ways that I know thatI can get the service to deserialize the "Data" property of ExecutionResults into a DataSet. One way would be to reference the library for ExecutionResults in the client, then the same ExecutionResults type will be used for the proxy when it is generated. Another way would be to not reference the library that holds "ExecutionResults" and let the proxy will create its own ExecutionResults class that implements IExtensibleDataObject. Then I can mark this class with [KnownType(typeof(DataSet))] in order to get the service to deserialize the "Data" property into a DataSet.

What is the right way to accomplish what I'm trying to do? It seems to me that both ways that I mentioned above involves some level of shared type knowledge between client and service. That is, it seems that in both scenarios that I'm enforcing that the service knows about a System.Data.DataSet. Is one of the scenarios I mentioned above less "evil" than the other?

A: 

Check out the DataSetSurrogate class: http://support.microsoft.com/kb/829740 It is specially designed for DataSet serialization.

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.

Flo
The DataContractSerializer that WCF uses by default, doesn't seem to have any difficulty serializing a DataSet.
SideFX
The size of a serialized DataSetSurrogate can be a lot smaller than a serialized DataSet.
Flo