Question

I am new to WCF and from what I have researched I understand it's not a good thing to return a dataset or a datatable from a WCF service. I also understand that the best way is convert your data into a DTO and then pass it on to the client.

The problem I am facing is that I need to create some reports that can have different number of columns and I only want to create one method in my web service to retrieve the data based on query name that will be supplied as a parameter. This makes it difficult for me to create a object class and map it to my data table as the number/type of columns would be different for each report.

What is the best way to achieve this? I have gone through a number of blogs but still haven't found a good way of doing this.

EDIT : I tried returning a datatable and got some errors which lead me to the blogs that explained why datasets/datatables were not a good idea for returning data in webservices.

Was it helpful?

Solution

Not sure about "the best way", but you can try to return xml file/xml string instead of DataTable from WCF. Convert your DataTable to xml using DataTable.WriteXml, then later service consumer can convert the xml back to DataTable using DataTable.ReadXml.

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