{"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有问题。非常感谢您的任何帮助!