Сбой службы wcf с обратным вызовом, возможно проблема с параллелизмом
У меня есть дуплексный сервис wcf. клиент регистрируется, а затем сервер вызывает обратный вызов. Обратный вызов принимает в качестве параметра список списка строк. так как это может быть очень большим, список делится на куски и обратный вызов вызывается несколько раз.
Вот код сервиса:
using Shared;
using System;
using System.Collections.Generic;
using System.IO;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Timers;
namespace CallbackService.Server
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, MaxItemsInObjectGraph = int.MaxValue)]
public class MyService : IMyService
{
public static IMyServiceCallback Callback;
public static Timer Timer;
public void OpenSession()
{
Console.WriteLine("> Session opened at {0}", DateTime.Now);
Callback = OperationContext.Current.GetCallbackChannel<IMyServiceCallback>();
Task.Factory.StartNew(() =>
{
GenerateListAndCallClient(null, null);
});
}
public static string RandomStr()
{
string rStr = Path.GetRandomFileName();
rStr = rStr.Replace(".", ""); // For Removing the .
return rStr;
}
void GenerateListAndCallClient(object sender, ElapsedEventArgs e)
{
List<List<string>> theList = new List<List<string>>();
for (int i = 0; i < 100; i++)
{
var innerList = new List<string>();
theList.Add(innerList);
for (int j = 0; j < 10000; j++)
{
innerList.Add(RandomStr());
}
}
int start = 0;
int count = 90;
while(start + count < theList.Count)
{
lock (typeof(MyService))
{
try
{
List<List<string>> currentList = theList.GetRange(start, count);
Callback.OnCallback(currentList);
start += count;
}
catch (ArgumentException) {
//skip last chunk
}
}
}
}
}
}
Установка счетчика в 1, все работает отлично. Обратный вызов вызывается 100 раз на клиенте. Установка количества в 90 дает исключение:
An exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll but was not handled in user codeAdditional information: 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:30'.
Любая идея?