EWS error gettingEvents

Im 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 receivean error:

ErrorNoRespondingCASInDestinationSite

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.

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.   


February 17th, 2015 7:33pm

Thank you very much, this has resolved the problem.  I still have alot of reading and figuring out to do with the links you posted there and trying to comply with it.  But as you see in the below snippet just adding and removing that header prior to and after the call has enabled me to GetEvents()

I am curious though, for your solution did you implement the whole solution [quote below] or did you do something similar to what im doing [code snippet below]?

"Using the GroupingInformation and ExternalEwsUrl settings from the Autodiscover responses, place mailboxes with the same ExternalEwsUrl and GroupingInformation concatenated value in the same group. If any groups have more than 200 mailboxes, break the groups down further so that each group has no more than 200 mailboxes."

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

Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 12:43pm

Your problem looks similar to mine (https://social.technet.microsoft.com/Forums/exchange/en-US/964c232d-48e3-47e9-a0e2-b8d9efe61aa7/ews-pull-notifications-stop-working-on-exchange-online).

Try to use X-AnchorMailbox header. See http://support.microsoft.com/kb/2990048/en-us and https://msdn.microsoft.com/en-us/library/office/dn458789%28v=exchg.150%29.aspx. 
  • Marked as answer by owen gerig 18 hours 26 minutes ago
February 18th, 2015 1:32pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics