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(IEnumerable
1 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.