views:

236

answers:

2

I am using a .NET web service as an interface to a database. What is the best way to return rows from this web service?

I vaguely remember that .NET 2.0 had issues with returning DataTable objects. Do those issues still exist?

Update: Some of the issues in .NET 1.1. Also, I believe that in 2.0 the DataTable is deserialized as a DataSet object on the client side. Am I correct?

+2  A: 

You're effectively trying to do the job of ADO.net? You much better off returning POCO (plain old c# objects) which you can serialize efficiently to send down soap then pull them back out at the other side. Perhaps you could give us some more information in your question as to what your trying to do.

DataRows and DataTables haven't changed in .net 3.0. If you want to use the entity framework to pass things around though you will run into different trouble. If they are rows, have a look at using Linq, and serializing then passing row entities as a collection. There are ways to reconstruct the entities into a data context on the client side so that the references link back up etc.

Spence
My web service fetches records from a database. I merely want to return the rows to the client. Returning a DataSet/DataTable should work but I've heard bad things about them back in .NET 2.0. Do any similar issues exist in .NET 3.0?
Vulcan Eager
What are those "bad things" actually? Performance?
Gerrie Schenck
No. Here are some links I found: http://support.microsoft.com/kb/306134 and http://bytes.com/groups/net-web-services/376326-possible-return-datatable-webservice-methodThese apply to .NET 2.0. How are in 3.0?
Vulcan Eager
That KB article applies to .Net 1.0 and 1.1. I use datatables with webservices a lot, and never had any problems.
Gerrie Schenck
+1  A: 

I would agree with Spence. With a web service you create a contract with the client. This contract should not be broken just because you want to change the shape of your database. I would create a class that matches the table structure and return a "list of" objects of this structure. Then, when the datamodel changes you can maintain this interface and create a second service method that matches the new structure.

Chris Simpson