gpt4 book ai didi

service - Exchange Web 服务 (EWS) 中的多个模拟线程

转载 作者:行者123 更新时间:2023-12-02 11:05:14 24 4
gpt4 key购买 nike

在 EWS 中运行多个用户模拟时,当我想要在每个模拟人员日历(可能是 100 人)上接收通知时,我遇到了问题。

目前我有一个 Outlook 帐户,该帐户有权模拟所有其他用户,并且所有 ExchangeService 对象都会获取此帐户凭据

简短的版本是,当我尝试通过唯一 ID 绑定(bind)到约会时,只要我只运行一个线程,它就可以工作。当我启动一个包含具有自己的订阅的新 Exchangeservice 的新线程时,我没有收到 Appointment.Bind() 请求的任何响应。

当我运行程序的两个实例时,每个实例中只有 1 个线程,它工作正常,但是一旦我使用新的 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)
{
}
}

有什么建议吗?

最佳答案

我也遇到了同样的问题,并发现我的 EWS 解决方案受到两个因素的限制。System.Net.ServicePointManager.DefaultConnectionLimit默认设置为 2,我已将其更改为 20,我相信这与 Exchange Online 的限制策略相匹配。

第二个ConnectionGroupName ExchangeService 对象上的属性可用于将连接汇集到不同的相关组中,这些组具有与 DefaultConnectionLimit 属性一致的并发连接限制。

覆盖这些设置的一种方法是将 ConnectionGroupName 属性设置为您创建的每个 ExchangeService 对象的唯一值。

ExchangeService exchangeService = new ExchangeService()
{
ConnectionGroupName = Guid.NewGuid().ToString()
};

关于service - Exchange Web 服务 (EWS) 中的多个模拟线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14436726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com