Search This Blog

Wednesday, October 19, 2011

Return Datatable from Web service in .Net

1) 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.
Cause:
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.


Solution :
To resolve this issue, return a DataSet instead of a DataTable. DataSet objects can contain one or more DataTable objects.

Popular Posts