1
votes

m having an issue with Office 365 EWS (its only Office 365, Exchange 2010 and 2013 work fine). I can create my pull subscription without error but when I go to use it by calling

getEvents()

I receive an error:

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.

Here is some code snippets

Using autodiscover and setting up credentials

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();
                    }

Afterwhich we Login and find our exchange user that we will perform all operations under

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");
                    }
                }

We then get a SubscribeResponse and save it to a list

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

We pass the above object into a wrapper method to get all Events from the 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;

The line that calls subscription.GetEvents() is where the exception indicated at the top is returned.
There is another layer of complexity added on because our Exchange user has a domain name of @FOOlab.onmicrosoft.com where as all of the rooms being managed have a domain name of @LAB.FOO.COM

According to the customer this is ADFS authentication, however I really don't know much about it.

I can say however that this code base did work (got events) and then something seemed to change and the error started popping up. Originally I thought the customer changed something but we have tested this against another Office 365 (without ADFS) and saw the same error, so now I don't know what to think.

1

1 Answers

4
votes

The links below can explain it far better then I can, but what I have done so far which has resolved my issue is to surround the GetEvents with the add and removal of the header data 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;
        }