Problems using an XML Web service that returns a DataTable
When you browse to the URL of an XML Web service that returns a DataTable from one of its Web methods, you may receive the following error message:
System.Data.DataRelation cannot be serialized because it does not have a default public constructor.
You may also see an error message similar to the following when you try to set a Web reference to this XML Web service in the Visual Studio .NET integrated development environment (IDE):
Internal Server Error. Unable to request “http://localhost/Webservice1/Service1.asmx?WSDL”. The server responded with error code “ProtocolError”.
With the .NET Framework 1.1 Service Pack 1 (SP1), you may receive the following error message:
System.NotSupportedException: Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface.
You may also receive a blank page instead of any of these error messages if Show friendly HTTP error messages is enabled in Microsoft Internet Explorer. By default, the Show friendly HTTP error messages option is enabled.
If you try to add a Web reference to an XML Web service that returns a DataTable, you may receive the following error message:
The document at the url http:///vdir/service1.asmx was not recognized as a known document type.
The DataTable, DataRow, DataView, and DataViewManager objects cannot be serialized and cannot be returned from an XML Web service. To return less than a complete DataSet, you must copy the data that you want to return to a new DataSet.
To resolve this issue, return a DataSet instead of a DataTable. DataSet objects can contain one or more DataTable objects.
Datatable is not returned through webservice beacause if you could, you could use for other non .net applications–and it a matter of policy I guess. But from the webservice prospective this should be considered a poor practice as well as from a service-orientation perspective. One of the tenets of service-orientation is that services share contract and schema … and nothing else. Passing a DataSet between Web services violates this tenet, and the result is that it will only work so long as both endpoints are always .NET platforms. (Microsoft products).
A better solution would be to pass entity data that is domain- or business-specific. Not a DataTable, but a set of data that has an actual XSD schema generated in the WSDL for the Web services so that it can be used by clients on any platform. (Microsoft doesnt want folks to use any other platform and so any support thereof is removed)