Returning DataTables (or DataSets) from WCF-Services is typically not a very good idea, for various reasons. The two most prominent ones being:
1) Clients other than .NET can't deal with it.
2) The default serialization performance is really bad.
Further reading:
c# - Returning DataTables in WCF/.NET - Stack Overflow[
^]
In general it does work though and, to be honest, I don't know from the top of my head what could be the cause of your problem.
But: If you're okay with clients having to be .NET then solving the second issue (serialization performance) will also solve your current problem here.
I'm using this library for serializing DataTables:
GitHub - rdingwall/protobuf-net-data: A library for serializing ADO.NET DataTables and DataReaders into a portable binary format.[
^]
With it you can serialize a DataTable into a byte-array (and deserialize it) independently from WCF. The return type of your WCF-method then would be
byte[]
instead of
DataTable
and WCF has no problem with that. Also the serialization performance is way better than the default one, both in speed as well as in size.
If you want to make it a bit prettier than using
byte[]
as the return type then you could create a custom class which holds the serialized DataTable and make that class the return type of your WCF-method. Benefit being that the name of the class type better describes the semantic content of the return value than
byte[]
if you name it "SerializedDataTable", for example. You could also put the required code for serialization and deserialization of the DataTable into that class so that it's nicely encapsulated.