I have a WCF service from which I want to return a DataTable. I know this is often a debatable topic about whether the data in the DataTables is true or not. Let's stop for a moment.
When I create a DataTable from scratch, as shown below, there is no problem. The table is created, populated and returned to the client, and all is well:
[DataContract] public DataTable GetTbl() { DataTable tbl = new DataTable("testTbl"); for(int i=0;i<100;i++) { tbl.Columns.Add(i); tbl.Rows.Add(new string[]{"testValue"}); } return tbl; }
However, as soon as I exit and enter the database to create a table, as shown below, I get a CommunicationException "The main connection was closed: the connection was unexpectedly closed."
[DataContract] public DataTable GetTbl() { DataTable tbl = new DataTable("testTbl");
The table is populated correctly on the server side. It is much smaller than the test table through which I looped and returned, and the request is small and fast - there are no problems with timeouts or large data transfers. The exact functions used are DataContracts / ServiceContracts / BehaviorContracts.
Why does the way the table is populated has anything to do with the table being returned?
goric Aug 15 '08 at 20:26 2008-08-15 20:26
source share