Wednesday, February 9, 2011

WCF Datatable, connection was closed and exception was thrown.

At the current time of writing I'am working on a project using the .net 3.5 sp1 Framework.

I encountered a strange error while trying to return a DataTable from a webservice using WCF. If the DataTable is initialized with the default constructor and no parameters are given then WCF cant serialize to object and return it to the client, the error thrown will look something like this:

An error occurred while receiving the HTTP response to *SERVICENAME* . This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Luckly the work around is easy :

just initialize the DataTable with the constructor where you specify a tableName, and then walla, the serialization works :)

Alternatively you can added the DataTable to a DataSet and return that to the client.

Happy Programming

No comments:

Post a Comment