Search code examples
c#wcfnettcpbinding

Serialization error while sending data table to WCF service


There was an error in serializing body of message Method1: 'There was an error generating the XML document.'

I am getting this error when I am trying to pass a data-table as a parameter to a WCF method, I have already used such type of methods (that is DataTable as parameter) in my WCF service, that works fine.

However in this case, I think the reason could be the size of the DataTable, not sure though.

Already tried increasing maxReceivedMessageSize, maxBufferSize and maxStringContentLength to 5242880 that is 5 MB (which I think is more than enough), but no luck.

Found many related articles, but no one pointing to this particular issue, hence posted.

Please guide.

Update:

My DataTable also contains contains some XML contents, can this be the issue, since this is serialized in XML format.


Solution

  • I had the same problem, but then i realized that i forgot to name the data table, just check if you are also missing it...

    DataTable dt = new DataTable();
    ...
    dt.TableName = "Table1";
    

    now pass the table as parameter, hope it helps