public static string DiscoverEwsUrl(IExchangePrincipal mailbox) { Uri uri; if (!EwsHelper.IsDatacenter) { EwsHelper.Tracer.TraceDebug(0L, "Not running in DC. Will use ServiceTopology to discover the url"); ServerVersion mailboxVersion = new ServerVersion(mailbox.MailboxInfo.Location.ServerVersion); IList <WebServicesService> list; try { ClientAccessType clientAccessType = EwsHelper.ClientAccessType; EwsHelper.Tracer.TraceDebug <ClientAccessType>(0L, "Will try to discover the URL for EWS with the following client access type: {0}", clientAccessType); ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Management\\EwsDriver\\EwsHelper.cs", "DiscoverEwsUrl", 119); list = currentServiceTopology.FindAll <WebServicesService>(mailbox, clientAccessType, delegate(WebServicesService service) { ServerVersion serverVersion = new ServerVersion(service.ServerVersionNumber); return(mailboxVersion.Major == serverVersion.Major && mailboxVersion.Minor <= serverVersion.Minor && !service.IsOutOfService); }, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Management\\EwsDriver\\EwsHelper.cs", "DiscoverEwsUrl", 121); } catch (LocalizedException arg) { EwsHelper.Tracer.TraceError <IExchangePrincipal, LocalizedException>(0L, "Unable to discover internal URL for EWS for mailbox {0} due exception {1}", mailbox, arg); return(null); } if (list.Count == 0) { EwsHelper.Tracer.TraceError <IExchangePrincipal>(0L, "Unable to find internal URL for EWS for mailbox {0}", mailbox); return(null); } WebServicesService webServicesService; if ((webServicesService = list.FirstOrDefault((WebServicesService service) => string.Equals(service.ServerFullyQualifiedDomainName, mailbox.MailboxInfo.Location.ServerFqdn, StringComparison.OrdinalIgnoreCase) && service.Url != null)) == null && (webServicesService = list.FirstOrDefault(delegate(WebServicesService service) { ServerVersion serverVersion = new ServerVersion(service.ServerVersionNumber); return(service.Url != null && mailboxVersion.Major == serverVersion.Major && mailboxVersion.Minor == serverVersion.Minor); })) == null) { webServicesService = list.FirstOrDefault((WebServicesService service) => service.Url != null); } WebServicesService webServicesService2 = webServicesService; uri = ((webServicesService2 == null) ? null : webServicesService2.Url); goto IL_1EA; } EwsHelper.Tracer.TraceDebug(0L, "Running in DC. Will use BackEndLocator to discover the url"); if (EwsHelper.discoveryEwsInternalUrl == null) { EwsHelper.discoveryEwsInternalUrl = (Func <IMailboxInfo, Uri>)Delegate.CreateDelegate(typeof(Func <IMailboxInfo, Uri>), Type.GetType("Microsoft.Exchange.Data.ApplicationLogic.Cafe.BackEndLocator, Microsoft.Exchange.Data.ApplicationLogic").GetMethod("GetBackEndWebServicesUrl", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(IMailboxInfo) }, null)); } uri = EwsHelper.discoveryEwsInternalUrl(mailbox.MailboxInfo); IL_1EA: if (!(uri == null)) { return(uri.ToString()); } return(null); }