We developed a SharePoint web part that displays selected users's calender items by requesting Exchange OnPrem 2013 or Exchange Online for users that have thier mailbox on Office 365. The code we're using is as follows :
// Impersonate the Search
ExchangeImpersonationType exchangeImpersonationType = new ExchangeImpersonationType();
ConnectingSIDType connectingSIDType = new ConnectingSIDType();
connectingSIDType.PrimarySmtpAddress = emailAddress;
exchangeImpersonationType.ConnectingSID = connectingSIDType;
exchangeServiceBinding.ExchangeImpersonation = exchangeImpersonationType;
// Create the Request
FindItemType findItemType = new FindItemType();
// Specified Transversal
findItemType.Traversal = ItemQueryTraversalType.Shallow;
// Specified ItemShape
ItemResponseShapeType itemResponseShapeType = new ItemResponseShapeType();
itemResponseShapeType.BaseShape = DefaultShapeNamesType.AllProperties;
findItemType.ItemShape = itemResponseShapeType;
// Specified ParentFolderIds
DistinguishedFolderIdType[] distinguishedFolderIdTypes = new DistinguishedFolderIdType[1];
distinguishedFolderIdTypes[0] = new DistinguishedFolderIdType();
distinguishedFolderIdTypes[0].Id = DistinguishedFolderIdNameType.calendar;
findItemType.ParentFolderIds = distinguishedFolderIdTypes;
// Specified Item
CalendarViewType calendarViewType = new CalendarViewType();
calendarViewType.StartDate = startDate;
calendarViewType.EndDate = endDate;
findItemType.Item = calendarViewType;
// Execute the Request
FindItemResponseType res = exchangeServiceBinding.FindItem(findItemType);
The issue is that when user doesn't have a mailbox on Exchange OnPrem, the exchangeServiceBinding.FindItem
method answers after 3 to 5 secondes with the error code "UserHasNoMailbox".
Imagine now loading a page with more thant 40 users and having 10 users among them that have mailbox on Exchange Online, we're losing at least 30 secondes in this case.
Is there any way to know if user has mailbox on Exchange OnPrem without making the FindItem
request ?
Thanks.