我有一个服务。我们向该服务发送记录。然而,当我们发送太多记录(3,000条)时,服务会超时。我的想法是将记录拆分并在每1,000条记录后打开服务,再关闭服务。
然而,我遇到了一个错误:
我创建了一个样例控制台应用程序以执行此操作,但是当我将其实际并入实际项目和实际服务时,出现错误。请问你能否帮我找出问题所在?我的猜测是client.open和client.close有问题。非常感谢您的任何帮助!
然而,我遇到了一个错误:
{"Cannot access a disposed object.\r\nObject name: 'System.ServiceModel.Channels.ServiceChannel'."}
这是我的代码:
ServiceClient client = new ServiceClient();
foreach (Record rc in creditTransactionList)
{
//if we are not on the last one...
if (currentTransCount < totalTransCount)
{
//Current batch count is less than 1,000
if (currentBatchCount <= amountPerBatch)
{
currentBatchCount++;
if (rc != null)
client.RecordInsert(rc);
}
//Current batch count is 1,000
if (currentBatchCount == amountPerBatch)
{
currentBatchCount = 0;
client.Close();
client.Open();
}
//Increment Total Counter by 1
currentTransCount++;
}
else
{
currentBatchCount++;
if (rc != null)
client.RecordInsert(rc);
client.Close();
}
}
amountPerBatch = 1000;
totalTransCount = ACHTransactionList.Count();
currentBatchCount = 0;
currentTransCount = 1;
foreach (Record rc in ACHTransactionList)
{
//if we are not on the last one...
if (currentTransCount < totalTransCount)
{
//Current batch count is less than 1,000
if (currentBatchCount <= amountPerBatch)
{
currentBatchCount++;
if (rc != null)
client.RecordInsert(rc);
}
//Current batch count is 1,000
if (currentBatchCount == amountPerBatch)
{
currentBatchCount = 0;
client.Close();
client.Open();
}
//Increment Total Counter by 1
currentTransCount++;
}
else
{
currentBatchCount++;
if (rc != null)
client.RecordInsert(rc);
client.Close();
}
}
我创建了一个样例控制台应用程序以执行此操作,但是当我将其实际并入实际项目和实际服务时,出现错误。请问你能否帮我找出问题所在?我的猜测是client.open和client.close有问题。非常感谢您的任何帮助!