Savan Patel
Savan Patel

Reputation: 339

Request failed because EWS could not contact the appropriate CAS server for this request

EWS subscription is being lost intermittently.It throws below two errors.

Error 1 Microsoft.Exchange.WebServices.Data.ServiceResponseException: The mailbox database is temporarily unavailable., Cannot open mailbox /o=ExchangeLabs/ou=Exchange Administrative Group

Error 2 Microsoft.Exchange.WebServices.Data.ServiceResponseException: Request failed because EWS could not contact the appropriate CAS server for this request. at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.SubscribeToStreamingNotifications(IEnumerable1 folderIds, EventType[] eventTypes)

I have used Exchange 2013 exchange service.

ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2013);
                exchange.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, _primaryMailbox);
                exchange.HttpHeaders.Add("X-AnchorMailbox", _primaryMailbox);
                exchange.HttpHeaders.Add("X-PreferServerAffinity", "true");

Below is the method for adding the subscription.

 ExchangeService exchange = group.ExchangeService;
                exchange.Credentials = new WebCredentials(BCCSettings.ImpersonatedUsername, BCCSettings.ImpersonatedPassword);
                exchange.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mailbox);

                subscription = exchange.SubscribeToStreamingNotifications(PreparFolders().ToArray(), EventType.NewMail, EventType.Moved);

Any help would be appreciated.

Upvotes: 3

Views: 2921

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

Error 1

That's normal its transient and will happen as backend servers are serviced (eg patches applied) and mailboxes are moved around on the backend for load balancing and other operational reasons. You client should catch and retry or recreate where necessary (eg if a Mailbox is moved between server or Datacenter it generally means that subscription is no longer valid and needs to recreated).

Error 2

Most likely its due to the same issue in Error 1 eg the Mailbox may have been moved to another Datacenter because the servers in the primary are being upgraded etc. If your using affinity https://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx you need to rediscover the Group the Mailbox is now associated with (which has mostly likely changed) and create a new subscription for that mailbox in that group.

Upvotes: 5

Related Questions