EWS 错误 ErrorNoRespondingCASInDestinationSite

EWS error ErrorNoRespondingCASInDestinationSite

m Office 365 EWS 有问题(只有 Office 365、Exchange 2010 和 2013 工作正常)。我可以毫无错误地创建我的请求订阅,但是当我通过调用

去使用它时
getEvents()

我收到一个错误:

ErrorNoRespondingCASInDestinationSite

The following error occured while retrieving events for exchange resource: - Exchange Web Services are not currently available for this request because none of the Client Access Servers in the destination site could process the request.

这是一些代码片段

使用自动发现和设置凭据

this.exchangeService.Credentials = new NetworkCredential(this.Username, this.Password);
                    try {
                        this.exchangeService.AutodiscoverUrl(this.Username, RedirectionCallback);
                    }
                    catch(Exception ex)
                    {
                        Logger.WriteToEventLog(EventLogEntryType.Warning, 104, "ExchangeDataAccess, AutodiscoverURL error: " + ex.Message);
                    }

                    if (exchangeService.Url == null)
                    {
                        this.ExchangeServerURL = GetOffice365EWSUrl(this.Username);
                        this.exchangeService.Url = new Uri(this.ExchangeServerURL);
                        this.exchangeService.CookieContainer = new CookieContainer();
                    }

之后我们登录并找到我们将在

下执行所有操作的交换用户
ServicePointManager.ServerCertificateValidationCallback = (sender1, certificate, chain, errors) => true;

                string username = this.Username;
                if (this.authenticateContext.GetExchangeServerVersion().Contains("365"))
                {
                    username = this.Username.Remove(this.Username.IndexOf("@"));
                }

                NameResolutionCollection resolveNameResult = this.exchangeService.ResolveName(username, ResolveNameSearchLocation.ContactsThenDirectory, true);

                if (resolveNameResult.Count() > 0)
                {
                    roomEmailAddress = resolveNameResult[0].Mailbox.Address;
                    if (!string.IsNullOrEmpty(roomEmailAddress))
                    {
                        this.ExchangeUserEmailAddress = roomEmailAddress;
                        logMsg.AppendLine("Logged into Exchange with " + roomEmailAddress + " successfully, RetrieveRoomsList is next");
                    }
                }

然后我们得到一个 SubscribeResponse 并将其保存到列表中

                subscribeResponse = this.exchangeDataAccess.ExchangeSubscribe(syncPoint.ThirdPartyId, syncPoint.Watermark, true);

我们将上述对象传递到包装器方法中以从 EWS 获取所有事件

        Dictionary<PullSubscription, IEnumerable<ItemEvent>> mailboxEvents = null;

        GetEventsResults eventsResults = subscription.GetEvents();

        if (eventsResults == null || eventsResults.ItemEvents.Count() == 0) {
            return mailboxEvents;
        }

        mailboxEvents = new Dictionary<PullSubscription, IEnumerable<ItemEvent>>();
        mailboxEvents.Add(subscription, eventsResults.ItemEvents);
        return mailboxEvents;

调用 subscription.GetEvents() 的行是返回顶部指示的异常的地方。
由于我们的 Exchange 用户的域名为@FOOlab.onmicrosoft.com,因此增加了另一层复杂性,而所有被管理的房间的域名为@LAB.FOO.COM

客户说这是ADFS认证,其实我也不是很了解

不过我可以说这个代码库确实有效(有事件),然后似乎发生了一些变化,错误开始弹出。最初我认为客户改变了一些东西,但我们已经针对另一个 Office 365(没有 ADFS)对此进行了测试并看到了同样的错误,所以现在我不知道该怎么想了。

下面的链接比我能解释得更好,但到目前为止我所做的解决我的问题的方法是围绕 GetEvents 添加和删​​除 header 数据 X-AnchorMailbox MSDN Link1 Link2

public Dictionary<PullSubscription, IEnumerable<ItemEvent>> GetEvents(SyncPoint syncpoint)
        {
            Dictionary<PullSubscription, IEnumerable<ItemEvent>> mailboxEvents = null; 

            if (this.authenticateContext.GetExchangeServerVersion().Contains("365"))
            {
                try
                {
                    //this is to maintain affinity (see here https://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx)
                    //it was added to fix an error: The following error occured while retrieving events for exchange resource: <room address> - Exchange Web Services are not currently available for this request because none of the Client Access Servers in the destination site could process the request.
                    //according to docs it is only when getting notifications that its important
                    if (this.exchangeService.HttpHeaders.Any(m => m.Key.Equals("X-AnchorMailbox")))
                    {
                        this.exchangeService.HttpHeaders.Remove("X-AnchorMailbox");
                    }
                    this.exchangeService.HttpHeaders.Add("X-AnchorMailbox", syncpoint.ThirdPartyId); //this is the email address of the mailbox being queried
                }
                catch { }
            }

            GetEventsResults eventsResults = syncpoint.pullSubscription.GetEvents();

            if (eventsResults == null || eventsResults.ItemEvents.Count() == 0)
            {
                return mailboxEvents;
            }

            mailboxEvents = new Dictionary<PullSubscription, IEnumerable<ItemEvent>>();
            mailboxEvents.Add(syncpoint.pullSubscription, eventsResults.ItemEvents);

            try
            {
                this.exchangeService.HttpHeaders.Remove("X-AnchorMailbox");
            } catch { }

            return mailboxEvents;
        }