EWS Exchange 使用一个 ExchangeService 连接模拟 2 个或更多用户

EWS Exchange Impersonate 2 or more users using one ExchangeService connection

为了避免 Exchange Server 限制 RCAMaxConcurrency (0-100),我想编写一个侦听器服务 (streamlistener),仅使用一个连接即可处理最多 5000 个用户。我已经拥有 200 个测试帐户和另一个对这 200 个测试帐户具有模拟权限的帐户。 如果可能的话,最好避免切换所有帐户。

我们已经有了代码,它可以很好地模拟 1 个用户。

public void SuscribeToCalendar()
{
    // Set the email address of the account to get the appointment.
    service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "xxxxxxxxx");
    // Subscribe to streaming notifications in the Inbox. 
    StreamingSubscription streamingSubscription = service.SubscribeToStreamingNotifications(
        new FolderId[] { WellKnownFolderName.Calendar }, EventType.Created, EventType.Modified, EventType.Moved);

    // Create a streaming connection to the service object, over which events are returned to the client.
    // Keep the streaming connection open for 30 minutes.
    StreamingSubscriptionConnection connection = new StreamingSubscriptionConnection(service, 30);
    connection.AddSubscription(streamingSubscription);
    connection.OnNotificationEvent += OnNotificationEvent;
    connection.OnDisconnect += OnDisconnect;
    connection.Open();
}

RCAMaxConcurrency 不会影响 EWS,它会影响使用 RPC 连接的 Outlook 连接。影响 EWS 的是 EWSMaxConcurrency,默认情况下它的值要低得多,为 10。 (您还会受到 20 的 EWSMaxSubscriptions 的影响)。

模拟设置会影响 EWS 请求的 header,因此您不能再模拟每次调用的一个用户,因此在创建订阅时,您需要为每个订阅的用户调用一次。您可以使用以下 https://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx 将订阅分组到一个与模拟的连接中。

组的限制是每个组 200 个用户,考虑到您订阅的流失量,您真的不想要这个了。当您使用模拟时,连接数不是问题,只要您不使用同一邮箱锚定任何组。

干杯 格伦