Data sent by WCF client is broken

Posted by Hemalbanugaria under WCF on 2/13/2012 | Points: 10 | Views : 3973 | Status : [Member] | Replies : 0
We are getting following exception in the .svclog file generated through system diagnostics config settings at server side.

Exception: System.ServiceModel.ProtocolException
Message: The number of bytes available is inconsistent with the HTTP Content-Length header. There may have been a network error or the client may be sending invalid requests.

We have observed that the data sent by WCF client is broken. We came to know about this by viewing the message xml in the .svclog file generated at WCF client side.

Actually we are sending data large data by dividing it into small chunks calling the WCF service method to send data in a loop. Following is the code for the same at WCF client side.

DataTable dtStockDetails = new DataTable("StockDetails");

int stockDetailsBatchSize = 100;
DataTable dtStockDetailsBatch = dtStockDetails.Clone();
DataRow dr;
int stockDetailsBatchCount = 0;
int stockDetailsTotalRecords = dtStockDetails.Rows.Count;

while (dtStockDetails.Rows.Count > 0)
dr = dtStockDetails.Rows[0];



if ((dtStockDetailsBatch.Rows.Count == stockDetailsBatchSize) || (dtStockDetails.Rows.Count == 0))
sendStockDetailsResult = serviceClient.SendStockDetails(dtStockDetailsBatch);

Now WCF client some times sends 7 batches of data, some times sends 9 batches of data, some times sends 10 batches of data, .... . In all cases lase message(data batch) xml gets corrupted. This behavior is random.

We are not sure why the message xml is getting corrupted and resulting into end of communication. It never sends all batches of data.

Attached "ServiceAndClient config" represents config settings.
WCF Service config settings (Web.config)
WCF Client config settings (App.config)

Can any one please suggest what should we do to resolve this problem?

Thanks in advance.


(No response found.)

Login to post response