Question

I am trying a host a service where there is a method that returns the following type:

[DataContract]
[Obfuscation(ApplyToMembers = true, Exclude = true)]
[Serializable]
public class Output
{
    [DataMember]
    public DataSet dsOutput{get;set;}
}

The method signature is as follows:

[OperationContract]
[WebGet]
function Output matchData(DataSet pDSSide1,DataSet pDSSide2)
{
   return new Output();
}

On browsing the service I encounter the following exception:

System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension:System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:TesterTool ---->

System.Runtime.Serialization.InvalidDataContractException: Type 'System.Data.DataRow' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types. `

Any suggestions.

Was it helpful?

Solution

It's not a good practice to send a DataTable over a service.

As stated by govindaraj here:

The best way is to use custom collection of custom object.

If you're using 2.0, then you can use generic collection instead of custom collection to reduce code.

How?

  1. Create a custom data object (containing only private fields and public properties for each field) that is similar to each row in the datatable.

  2. Create a layer that will do all database (in this case, dataset) access and translation to the custom object.

  3. All client code will access that layer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top