Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I serialize a Data Table or Data Set to transfer over a Web Service in C#?

I am using a web service to query data from a table. Then I have to send it to a user who wants it as a DataTable. Can I serialize the data? Or should I send it as A DataSet. I am new to Web Services, so I am not sure the best way to do it.

like image 294
Loganj99 Avatar asked Feb 18 '09 14:02

Loganj99


2 Answers

You can send the data as a xml string from a dataset by DataSet.GetXml()

And than the user can deserialize it with DataSet.ReadXml()

And get the datatable from the dataset by DataSet.Tables

Good luck

like image 130
freggel Avatar answered Sep 30 '22 19:09

freggel


If you expose it as a DataSet/DataTable, it will do its own serialization anyway (via IXmlSerializable, IIRC). Note that DataSet/DataTable don't make for good data-types on web services if you want the service to be portable to other patforms (i.e. a java client, etc). But you can simply expose it as such if you want...; .NET will deal with the translation.

like image 44
Marc Gravell Avatar answered Sep 30 '22 20:09

Marc Gravell