I am working on University Management System on which I am using a WCF service and in the service I am using DataTables and DataSets for getting data from database and database is sql server.
My questions are
- Is using DataTables and Datasets "Good Practice" or "Bad Practice" ?
- If it is bad, what is the alternative of DataTable/DataSet ?
- If it is bad, what are the main reasons ?
There are 3 reason for failed return type as
datatable
in WCF servicesYou have to specify data table name like:
When you are adding reference on client side of WCF service select reusable dll
system.data
Specify attribute on
datatable
member variable likeReturning data sets from web services is not typically considered a “good practice”. The issues have been documented thoroughly in the following links:
http://msdn.microsoft.com/en-us/magazine/cc163751.aspx
http://www.4guysfromrolla.com/articles/051805-1.aspx
http://msdn.microsoft.com/en-us/magazine/cc188755.aspx
In summary, the biggest issues with returning
DataSet
objects from web services seem to involve serialization performance, non-.net interoperability. In addition, the generic, polymorphic nature of theDataSet
generally high the data structure until runtime, as such, the WSDL definition does not provide a complete description of the method signature. As with any design decision, however, you need to weigh the costs vs the benefits and determine the best fit given your specific goals and constraints.In terms of alternatives, you could consider using a generic collection (e.g.
List<yourClassHere>
) or maybe even consider some architecture revisions to permit the use of ODATA.The following links provide some good background reference for returning entities via web services. http://msdn.microsoft.com/en-us/library/orm-9780596520281-01-14.aspx http://www.codeproject.com/Articles/127395/Implementing-a-WCF-Service-with-Entity-Framework http://msdn.microsoft.com/en-us/data/hh237663.aspx
I am using
DataTable
in my WCF application, but was getting an error. This is how I fixed the error.When returning a DataTable from a web service in WCF to windows form application. I was getting this exception.
It happened any time I tried to retrieve a
DataTable
To fix the exception I needed to give the
DataTable
a name.code with the error
Fixed code to remove the excption