Reputation: 3
I'm creating an application for manage stock from a distance for Windows, in C#.
My client-server communication works, I can exchange some String, bool, int, etc. But I can't get DataTable or other kind of objects from the server. Currently I do my tests with few data in my database, the server managed to read the data when client call the function but the client doesn't recieve the function return (a DataTable).
This is my error message:
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.2590000'.
My host:
NetTcpBinding netTcpBinding = new NetTcpBinding();
netTcpBinding.MaxBufferSize = 10000000;
netTcpBinding.MaxReceivedMessageSize = 10000000;
netTcpBinding.CloseTimeout = TimeSpan.FromMinutes(10);
netTcpBinding.SendTimeout = TimeSpan.FromMinutes(10);
ServiceHost host = new ServiceHost(typeof(ServiceWCF));
host.AddServiceEndpoint(typeof(ISLM_serviceContract),
netTcpBinding,"net.tcp://localhost:10108/SLM_WCF");
host.Open();
Any suggestions are greatly appreciated. Thanks in advance
Upvotes: 0
Views: 1059
Reputation: 3071
While I strongly agree with @Lucas point, to avoid using DataTable
whenever you can in WCF
, I would suggest a possible solution to the problem, in case you have to use DataTable
for some reasons.
Since you setup TimeOut
and MessageSize
to really big numbers, I would suspect this is actually a problem with serialization of the message. In particular, you will have this problem if you do not set the name of the DataTable
when creating it.
public DataTable MyServiceMethod()
{
DataTable dataTable = new DataTable();
// populate dataTable;
return dataTable;
}
If this is how you're creating data table, it might fail to serialize, instead you need to give a name to the dataTable
DataTable dataTable = new DataTable("myDataTable);
Upvotes: 1
Reputation: 51430
Stop using DataTable
. Yes, really: they are a pain to use, so why bother? And in top of that, you loose strong typing.
More seriously, this is caused by the fact that WCF needs to know beforehand the format on your message, and loosely typed values won't do with the default serializer (DataContractSerializer
).
So you may either switch the serializer to NetDataContractSerializer
, which should be able to handle this kind of scenario (I never tested it with DataTable
but I suppose it could work).
Or the better solution: create an object of your own (strongly typed), that represents a row and return a list of that.
Upvotes: 0