在 EWS 中运行多个用户模拟时遇到问题,当我想在每个模拟人日历(可能 100 人)上接收通知时。
目前我有一个有权模拟所有其他用户的 Outlook 帐户,并且所有 ExchangeService 对象都获得此帐户凭据
简短的版本是,当我尝试通过唯一 ID 绑定到约会时,只要我只有一个线程在运行,它就可以工作。当我启动一个包含具有自己订阅的新 Exchangeservice 的新线程时,我没有收到任何关于 Appointment.Bind()-request 的响应。
当我运行我的程序的两个实例时,每个实例只有一个线程,它工作正常,但是一旦我使用新的 ExchangeService 启动一个新线程,Appointment.Bind() 就不会给出任何响应。
奇怪的是,两周前它运行良好,但突然停止运行,我没有更改我的代码。
我创建了一个我的问题的快速演示:
class Program
{
static void Main(string[] args)
{
var x = new OutlookListener("user1@server.com");
var y = new OutlookListener("user2@server.com");
new Thread(x.Start).Start();
new Thread(y.Start).Start();
while (true)
{
}
}
}
class OutlookListener
{
private ExchangeService _ExchangeService;
private AutoResetEvent _Signal;
public OutlookListener(string emailToImp)
{
_ExchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
Credentials = new NetworkCredential("superuser@server.com", "password"),
Url = new Uri("exchangeUrl"),
ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailToImp)
};
}
public void Start()
{
var subscription = _ExchangeService.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Calendar },
EventType.Created);
var connection = CreateStreamingSubscription(_ExchangeService, subscription);
Console.Out.WriteLine("Subscription created.");
_Signal = new AutoResetEvent(false);
_Signal.WaitOne();
subscription.Unsubscribe();
connection.Close();
}
private StreamingSubscriptionConnection CreateStreamingSubscription(ExchangeService service, StreamingSubscription subscription)
{
var connection = new StreamingSubscriptionConnection(service, 30);
connection.AddSubscription(subscription);
connection.OnNotificationEvent += OnNotificationEvent;
connection.OnSubscriptionError += OnSubscriptionError;
connection.OnDisconnect += OnDisconnect;
connection.Open();
return connection;
}
private void OnNotificationEvent(object sender, NotificationEventArgs args)
{
// Extract the item ids for all NewMail Events in the list.
var newMails = from e in args.Events.OfType<ItemEvent>()
where e.EventType == EventType.Created
select e.ItemId;
foreach (var newMail in newMails)
{
var appointment= Appointment.Bind(_ExchangeService, newMail); //This is where I dont get a response!
Console.WriteLine(appointment.Subject);
}
}
private void OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
{
}
private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
{
}
}
有什么建议么?