internal MeetingValidatorEwsBinding(ExchangePrincipal principal, Uri endpoint) : base("ExchangeCalendarRepairAssistant", new RemoteCertificateValidationCallback(MeetingValidatorEwsBinding.CertificateErrorHandler))
 {
     this.RequestServerVersionValue = MeetingValidatorEwsBinding.RequestServerVersionExchange2013;
     base.UserAgent = "ExchangeCalendarRepairAssistant";
     base.Url       = endpoint.AbsoluteUri;
     base.Timeout   = (int)TimeSpan.FromSeconds((double)Configuration.WebRequestTimeoutInSeconds).TotalMilliseconds;
     NetworkServiceImpersonator.Initialize();
     if (NetworkServiceImpersonator.Exception == null)
     {
         base.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
         base.Authenticator.AdditionalSoapHeaders.Add(new OpenAsAdminOrSystemServiceType
         {
             ConnectingSID = new ConnectingSIDType
             {
                 Item = new SmtpAddressType
                 {
                     Value = principal.MailboxInfo.PrimarySmtpAddress.ToString()
                 }
             },
             LogonType           = SpecialLogonType.SystemService,
             BudgetType          = 1,
             BudgetTypeSpecified = true
         });
     }
 }
 // Token: 0x06001C62 RID: 7266 RVA: 0x000714E0 File Offset: 0x0006F6E0
 public FindInGALSpeechRecognitionEWSBinding(SmtpAddress orgMboxSmtpAddress, Uri serviceUri, object state) : base("FindInGALSpeechRecognition", new RemoteCertificateValidationCallback(FindInGALSpeechRecognitionEWSBinding.CertificateErrorHandler))
 {
     ValidateArgument.NotNull(orgMboxSmtpAddress, "orgMboxSmtpAddress");
     ValidateArgument.NotNull(serviceUri, "serviceUri");
     ValidateArgument.NotNull(state, "state");
     base.Url = serviceUri.ToString();
     this.RequestServerVersionValue = FindInGALSpeechRecognitionEWSBinding.RequestServerVersion;
     base.UserAgent     = "FindInGALSpeechRecognition";
     base.Proxy         = new WebProxy();
     base.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
     base.Authenticator.AdditionalSoapHeaders.Add(new OpenAsAdminOrSystemServiceType
     {
         ConnectingSID = new ConnectingSIDType
         {
             Item = new SmtpAddressType
             {
                 Value = orgMboxSmtpAddress.ToString()
             }
         },
         LogonType           = SpecialLogonType.SystemService,
         BudgetType          = 2,
         BudgetTypeSpecified = true
     });
     this.State = state;
     NetworkServiceImpersonator.Initialize();
 }
 public HttpWebResponse AuthenticateAndGetResponse(HttpWebRequest request)
 {
     ArgumentValidator.ThrowIfNull("request", request);
     NetworkServiceImpersonator.Initialize();
     this.tracer.TraceDebug <string>((long)this.GetHashCode(), "LOCAL FOREST OTHER SERVER OUTBOUND AUTHENTICATOR: stamping component id '{0}' onto request.", this.certificateValidationComponentId);
     CertificateValidationManager.SetComponentId(request, this.certificateValidationComponentId);
     request.PreAuthenticate = true;
     return(HttpAuthenticator.NetworkService.AuthenticateAndExecute <HttpWebResponse>(request, () => (HttpWebResponse)request.GetResponse()));
 }
        private HttpWebRequest GetProxyRequest(int contentLength)
        {
            NetworkServiceImpersonator.Initialize();
            if (NetworkServiceImpersonator.Exception != null)
            {
                ExTraceGlobals.ProxyCallTracer.TraceError <LocalizedException>(0L, "Unable to impersonate network service to call EWS due exception {0}", NetworkServiceImpersonator.Exception);
                throw new AsyncExceptionWrapper(NetworkServiceImpersonator.Exception);
            }
            HttpWebRequest httpWebRequest = ProxyUtilities.CreateHttpWebRequestForProxying(base.OwaContext, this.proxyRequestUrl);

            httpWebRequest.Method          = "POST";
            httpWebRequest.ContentType     = this.HttpContext.Request.ContentType;
            httpWebRequest.ContentLength   = (long)contentLength;
            httpWebRequest.UserAgent       = "OwaProxy";
            httpWebRequest.PreAuthenticate = true;
            return(httpWebRequest);
        }
		private static ExchangeServiceBinding CreateBinding(string email)
		{
			NetworkServiceImpersonator.Initialize();
			if (NetworkServiceImpersonator.Exception != null)
			{
				ExTraceGlobals.ELCTracer.TraceError<LocalizedException>(0L, "Unable to impersonate network service to call EWS due to exception {0}", NetworkServiceImpersonator.Exception);
				throw new ElcUserConfigurationException(Strings.ElcUserConfigurationServiceBindingNotAvailable, NetworkServiceImpersonator.Exception);
			}
			ExchangeServiceBinding exchangeServiceBinding = new ExchangeServiceBinding(new RemoteCertificateValidationCallback(StoreRetentionPolicyTagHelper.CertificateErrorHandler));
			exchangeServiceBinding.UserAgent = WellKnownUserAgent.GetEwsNegoAuthUserAgent("MRMTask");
			exchangeServiceBinding.RequestServerVersionValue = new RequestServerVersion
			{
				Version = ExchangeVersionType.Exchange2010_SP1
			};
			StoreRetentionPolicyTagHelper.SetSecurityHeader(exchangeServiceBinding, email);
			return exchangeServiceBinding;
		}
 public void Impersonate(ImpersonateDelegate impersonateDelegate)
 {
     if (this.credentials != null)
     {
         impersonateDelegate(this.credentials);
         return;
     }
     NetworkServiceImpersonator.Initialize();
     if (NetworkServiceImpersonator.Exception != null)
     {
         impersonateDelegate(CredentialCache.DefaultNetworkCredentials);
         return;
     }
     using (NetworkServiceImpersonator.Impersonate())
     {
         impersonateDelegate(CredentialCache.DefaultNetworkCredentials);
     }
 }
 internal UpdateGroupMailboxEwsBinding(ADUser group, Uri ewsEndpoint) : base("GroupMailboxCmdlet", new RemoteCertificateValidationCallback(CommonCertificateValidationCallbacks.InternalServerToServer))
 {
     ArgumentValidator.ThrowIfNull("group", group);
     ArgumentValidator.ThrowIfNull("ewsEndpointUrl", ewsEndpoint);
     base.Url = ewsEndpoint.ToString();
     base.HttpHeaders[WellKnownHeader.EWSTargetVersion] = EwsTargetVersion.V2_14;
     base.UserAgent = "GroupMailboxCmdlet";
     base.Proxy     = new WebProxy();
     base.SetClientRequestIdHeaderFromActivityId();
     using (new StopwatchPerformanceTracker("UpdateGroupMailboxEwsBinding.CreateNetworkService", GenericCmdletInfoDataLogger.Instance))
     {
         base.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
     }
     using (new StopwatchPerformanceTracker("UpdateGroupMailboxEwsBinding.InitNetworkServiceImpersonator", GenericCmdletInfoDataLogger.Instance))
     {
         NetworkServiceImpersonator.Initialize();
     }
 }
        public virtual IExchangeService CreateBinding(RemoteCertificateValidationCallback certificateErrorHandler)
        {
            bool flag = true;

            NetworkServiceImpersonator.Initialize();
            if (NetworkServiceImpersonator.Exception != null)
            {
                if (this.IsTraceEnabled(TraceType.ErrorTrace))
                {
                    this.Tracer.TraceError <LocalizedException>(0L, "Unable to impersonate network service to call EWS due to exception {0}", NetworkServiceImpersonator.Exception);
                }
                flag = false;
            }
            ExchangeServiceBinding exchangeServiceBinding = new ExchangeServiceBinding(certificateErrorHandler);

            exchangeServiceBinding.UserAgent = WellKnownUserAgent.GetEwsNegoAuthUserAgent("AuditLog");
            exchangeServiceBinding.RequestServerVersionValue = new RequestServerVersion
            {
                Version = ExchangeVersionType.Exchange2013
            };
            if (flag)
            {
                exchangeServiceBinding.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
            }
            else
            {
                exchangeServiceBinding.Authenticator = SoapHttpClientAuthenticator.Create(CredentialCache.DefaultCredentials);
            }
            exchangeServiceBinding.Authenticator.AdditionalSoapHeaders.Add(new OpenAsAdminOrSystemServiceType
            {
                ConnectingSID = new ConnectingSIDType
                {
                    Item = new PrimarySmtpAddressType
                    {
                        Value = this.GetSmtpAddress()
                    }
                },
                LogonType           = SpecialLogonType.SystemService,
                BudgetType          = (int)this.budgetType,
                BudgetTypeSpecified = true
            });
            return(exchangeServiceBinding);
        }
Пример #9
0
        private static void Initialize(RequestLogger requestLogger)
        {
            requestLogger.CaptureRequestStage("CRInit");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is now initializing NetworkServiceImpersonator.");
            NetworkServiceImpersonator.Initialize();
            requestLogger.CaptureRequestStage("CRNSInit");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is done initializing NetworkServiceImpersonator.");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is now initializing Dns for AS discovery.");
            AutoDiscoverDnsReader.Initialize();
            requestLogger.CaptureRequestStage("CRAD");
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is done initializing Dns for AS discovery.");
            DateTime populateDeadline = DateTime.UtcNow + ConfigurationReader.initializeTimeInterval;

            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is now refreshing TargetForestConfigurationCache.");
            TargetForestConfigurationCache.Populate(populateDeadline);
            ConfigurationReader.ConfigurationTracer.TraceDebug(0L, "ConfigurationReader is done refreshing TargetForestConfigurationCache.");
            requestLogger.CaptureRequestStage("CRTC");
            ConfigurationReader.ASFaultInjectionTracer.RegisterExceptionInjectionCallback(new ExceptionInjectionCallback(FaultInjection.Callback));
            ConfigurationReader.RequestDispatchFaultInjectionTracer.RegisterExceptionInjectionCallback(new ExceptionInjectionCallback(FaultInjection.Callback));
        }
Пример #10
0
        internal MailboxAssociationEwsBinding(ADUser user, OpenAsAdminOrSystemServiceBudgetTypeType budgetType) : base("GroupMailboxAccessLayer", new RemoteCertificateValidationCallback(CommonCertificateValidationCallbacks.InternalServerToServer))
        {
            ArgumentValidator.ThrowIfNull("user", user);
            ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(user, null);

            MailboxAssociationEwsBinding.Tracer.TraceDebug <bool>((long)this.GetHashCode(), "MailboxAssociationEwsBinding.ctor - ExchangePrincipal.MailboxInfo.Location is null? {0}", exchangePrincipal.MailboxInfo.Location == null);
            Uri ewsEndpoint = null;

            MailboxAssociationEwsBinding.ExecuteEwsOperationWithRetry("GetBackEndWebServicesUrl", delegate
            {
                ewsEndpoint = BackEndLocator.GetBackEndWebServicesUrl(exchangePrincipal.MailboxInfo);
            });
            if (ewsEndpoint == null)
            {
                throw new MailboxNotFoundException(Strings.EwsUrlDiscoveryFailed(user.PrimarySmtpAddress.ToString()));
            }
            base.Url = ewsEndpoint.ToString();
            if (string.IsNullOrEmpty(base.Url))
            {
                throw new MailboxNotFoundException(Strings.EwsUrlDiscoveryFailed(user.PrimarySmtpAddress.ToString()));
            }
            base.HttpHeaders[WellKnownHeader.EWSTargetVersion] = EwsTargetVersion.V2_7;
            base.UserAgent = "GroupMailboxAccessLayer";
            base.Proxy     = new WebProxy();
            base.SetClientRequestIdHeaderFromActivityId();
            base.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
            base.Authenticator.AdditionalSoapHeaders.Add(new OpenAsAdminOrSystemServiceType
            {
                ConnectingSID = new ConnectingSIDType
                {
                    Item = new SmtpAddressType
                    {
                        Value = user.PrimarySmtpAddress.ToString()
                    }
                },
                LogonType           = SpecialLogonType.Admin,
                BudgetType          = (int)budgetType,
                BudgetTypeSpecified = true
            });
            NetworkServiceImpersonator.Initialize();
        }
        private IEnumerator <int> ProcessProxyRequest(AsyncEnumerator ae)
        {
            ExTraceGlobals.ProxyCallTracer.TraceDebug((long)this.GetHashCode(), "ProxyEventHandler.SendProxyRequest");
            base.DontWriteHeaders = true;
            int newContentLength = 0;

            byte[]         soapHeaderStuff      = this.GetRequestSoapHeader(out newContentLength);
            HttpWebRequest webRequest           = this.GetProxyRequest(newContentLength);
            WindowsImpersonationContext context = NetworkServiceImpersonator.Impersonate();

            try
            {
                ae.AddAsync <IAsyncResult>(webRequest.BeginGetRequestStream(ae.GetAsyncCallback(), null));
            }
            catch
            {
                context.Undo();
                context = null;
                throw;
            }
            finally
            {
                if (context != null)
                {
                    context.Undo();
                    context = null;
                }
            }
            yield return(1);

            Stream outStream = this.DoWebAction <Stream>(() => webRequest.EndGetRequestStream(ae.CompletedAsyncResults[0]));

            if (outStream == null)
            {
                ae.End();
            }
            else
            {
                using (outStream)
                {
                    ae.AddAsync <IAsyncResult>(outStream.BeginWrite(soapHeaderStuff, 0, soapHeaderStuff.Length, ae.GetAsyncCallback(), null));
                    yield return(1);

                    outStream.EndWrite(ae.CompletedAsyncResults[0]);
                    AsyncResult asyncResult = ae.AddAsyncEnumerator((AsyncEnumerator ae1) => ProxyToEwsEventHandler.CopyStream(ae1, this.HttpContext.Request.InputStream, outStream));
                    yield return(1);

                    asyncResult.End();
                }
                ae.AddAsync <IAsyncResult>(webRequest.BeginGetResponse(ae.GetAsyncCallback(), null));
                yield return(1);

                HttpWebResponse webResponse = this.DoWebAction <HttpWebResponse>(() => (HttpWebResponse)webRequest.EndGetResponse(ae.CompletedAsyncResults[0]));
                if (webResponse != null)
                {
                    using (webResponse)
                    {
                        ae.AddAsyncEnumerator((AsyncEnumerator ae1) => this.ProcessWebResponse(ae1, webResponse));
                        yield return(1);
                    }
                }
                ae.End();
            }
            yield break;
        }
Пример #12
0
        public IAsyncResult BeginProcessRequest(HttpContext context, IAsyncResult asyncResult, ProxyHandler.ProxiedRequestInfo proxyinfo)
        {
            LazyAsyncResult lazyAsyncResult = (LazyAsyncResult)asyncResult;

            this.proxyInfo = proxyinfo;
            this.remoteUri = this.proxyInfo.RemoteUri;
            this.userName  = this.proxyInfo.User;
            try
            {
                AirSyncDiagnostics.TraceDebug <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest called for serverName: {0}, user {1}", this.remoteUri, this.userName);
                if (!string.Equals(context.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) && !string.Equals(context.Request.HttpMethod, "OPTIONS", StringComparison.OrdinalIgnoreCase))
                {
                    context.Response.StatusCode = 405;
                    lazyAsyncResult.InvokeCallback();
                    return(lazyAsyncResult);
                }
                UriBuilder uriBuilder = new UriBuilder(this.proxyInfo.RemoteUri);
                if (!string.IsNullOrEmpty(context.Request.Url.Query))
                {
                    if (!string.IsNullOrEmpty(context.Request.Url.Fragment))
                    {
                        string str = context.Request.Url.Fragment.Remove(0, 1);
                        uriBuilder.Query = context.Request.Url.Query.Remove(0, 1) + "%23" + str;
                    }
                    else
                    {
                        uriBuilder.Query = context.Request.Url.Query.Remove(0, 1);
                    }
                }
                this.cachedUri = uriBuilder.Uri;
                HttpWebRequest httpWebRequest = this.CopyClientRequest(context.Request, this.cachedUri);
                WindowsImpersonationContext windowsImpersonationContext = null;
                IAsyncResult asyncResult2 = null;
                try
                {
                    if (this.proxyInfo.RequiresImpersonation)
                    {
                        windowsImpersonationContext = ((WindowsIdentity)context.User.Identity).Impersonate();
                    }
                    else
                    {
                        NetworkServiceImpersonator.Initialize();
                        windowsImpersonationContext = NetworkServiceImpersonator.Impersonate();
                        httpWebRequest.Credentials  = CredentialCache.DefaultCredentials;
                    }
                    this.backEndWebRequest   = httpWebRequest;
                    this.frontEndResult      = lazyAsyncResult;
                    this.frontEndHttpContext = context;
                    try
                    {
                        this.clientRequestStream = this.frontEndHttpContext.Request.InputStream;
                    }
                    catch (COMException innerException)
                    {
                        this.protocolLogger.SetValue(ProtocolLoggerData.Error, "InputStreamUnavailable");
                        throw new AirSyncPermanentException(HttpStatusCode.ServiceUnavailable, StatusCode.ServerErrorRetryLater, innerException, false);
                    }
                    this.issueTime             = ExDateTime.Now;
                    this.pendingAsyncOperation = ProxyHandler.PendingOperationState.BackEndGetRequestStream;
                    asyncResult2 = this.backEndWebRequest.BeginGetRequestStream(new AsyncCallback(this.BackEndGetRequestStream), null);
                }
                finally
                {
                    if (windowsImpersonationContext != null)
                    {
                        windowsImpersonationContext.Undo();
                        windowsImpersonationContext.Dispose();
                    }
                }
                if (asyncResult2 != null && !asyncResult2.CompletedSynchronously)
                {
                    this.RegisterTimeoutWaitHandle(asyncResult2, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
                }
            }
            catch (Exception ex)
            {
                AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
                AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest caught an exception\r\n{0}", arg);
                if (this.backEndWebRequest != null)
                {
                    this.backEndWebRequest.Abort();
                    this.backEndWebRequest = null;
                }
                if (ex is WebException)
                {
                    AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest swallowing exception and returning HTTP 500");
                    try
                    {
                        this.TryUnregisterTimeoutWaitHandle();
                        this.frontEndHttpContext.Response.StatusCode = 500;
                        this.frontEndResult.InvokeCallback();
                        goto IL_2F0;
                    }
                    catch (HttpException ex2)
                    {
                        AirSyncUtility.ExceptionToStringHelper arg2 = new AirSyncUtility.ExceptionToStringHelper(ex2);
                        AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "HttpException was thrown while setting the StatusCode.\r\n{0}", arg2);
                        goto IL_2F0;
                    }
                    goto IL_2EE;
IL_2F0:
                    return(lazyAsyncResult);
                }
IL_2EE:
                throw;
            }
            return(lazyAsyncResult);
        }
Пример #13
0
        protected override IAsyncResult BeginInvoke()
        {
            this.timer = Stopwatch.StartNew();
            string xmlBody = this.GetXmlBody();

            byte[] bytes = Encoding.UTF8.GetBytes(xmlBody);
            WindowsImpersonationContext windowsImpersonationContext = null;
            Exception ex = null;

            try
            {
                this.request             = (HttpWebRequest)WebRequest.Create(this.targetUri);
                this.request.Method      = "POST";
                this.request.ContentType = "text/xml";
                this.request.Headers.Add("X-AnchorMailbox", this.emailAddress.Address);
                if (this.credentialsForDiscovery == null)
                {
                    if (Testability.WebServiceCredentials == null)
                    {
                        windowsImpersonationContext = NetworkServiceImpersonator.Impersonate();
                        this.impersonating          = true;
                    }
                    this.credentialsForDiscovery = CredentialCache.DefaultCredentials;
                    this.request.Credentials     = this.credentialsForDiscovery;
                }
                else
                {
                    CredentialCache credentialCache = new CredentialCache();
                    credentialCache.Add(this.targetUri, "Basic", (NetworkCredential)this.credentialsForDiscovery);
                    this.request.Credentials     = credentialCache;
                    this.request.PreAuthenticate = true;
                }
                this.request.Timeout           = (int)this.timeout.TotalMilliseconds;
                this.request.UserAgent         = this.GetUserAgent();
                this.request.AllowAutoRedirect = false;
                this.request.ContentLength     = (long)bytes.Length;
                if (this.bypassProxy)
                {
                    this.request.Proxy = new WebProxy();
                }
                CertificateValidationManager.SetComponentId(this.request, Globals.CertificateValidationComponentId);
                using (Stream requestStream = this.request.GetRequestStream())
                {
                    requestStream.Write(bytes, 0, bytes.Length);
                }
                AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Sending request to AutoDiscover service, xml body: {1}", TraceContext.Get(), xmlBody);
                if (base.Aborted)
                {
                    this.request.Abort();
                }
                return(this.request.BeginGetResponse(new AsyncCallback(base.Complete), null));
            }
            catch (ProtocolViolationException ex2)
            {
                ex = ex2;
            }
            catch (SecurityException ex3)
            {
                ex = ex3;
            }
            catch (ArgumentException ex4)
            {
                ex = ex4;
            }
            catch (InvalidOperationException ex5)
            {
                ex = ex5;
            }
            catch (NotSupportedException ex6)
            {
                ex = ex6;
            }
            catch (XmlException ex7)
            {
                ex = ex7;
            }
            catch (XPathException ex8)
            {
                ex = ex8;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (windowsImpersonationContext != null)
                {
                    windowsImpersonationContext.Dispose();
                    this.impersonating = false;
                }
            }
            if (ex != null)
            {
                this.HandleException(ex);
            }
            return(null);
        }
        private static void SyncInternal(MailboxSession mailboxSession, ExDateTime lastSyncTime, StoreId folderId, string folderDisplayname, SecurityAccessToken securityAccessToken)
        {
            RefreshSharingFolderClient.Tracer.TraceDebug <string, IExchangePrincipal>(0L, "Sync sharing folder {0} from mailbox {1}", folderDisplayname, mailboxSession.MailboxOwner);
            if (!RefreshSharingFolderClient.CanSyncNow(lastSyncTime))
            {
                return;
            }
            NetworkServiceImpersonator.Initialize();
            if (NetworkServiceImpersonator.Exception != null)
            {
                RefreshSharingFolderClient.Tracer.TraceError <LocalizedException>(0L, "Unable to impersonate network service to call EWS due exception {0}", NetworkServiceImpersonator.Exception);
                return;
            }
            string id = StoreId.StoreIdToEwsId(mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, folderId);
            IList <WebServicesService> list;

            try
            {
                ClientAccessType clientAccessType = RefreshSharingFolderClient.ClientAccessType;
                RefreshSharingFolderClient.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\\Sharing\\RefreshSharingFolderClient.cs", "SyncInternal", 153);
                list = currentServiceTopology.FindAll <WebServicesService>(mailboxSession.MailboxOwner, clientAccessType, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\RefreshSharingFolderClient.cs", "SyncInternal", 154);
            }
            catch (LocalizedException arg)
            {
                RefreshSharingFolderClient.Tracer.TraceError <IExchangePrincipal, LocalizedException>(0L, "Unable to discover internal URL for EWS for mailbox {0} due exception {1}", mailboxSession.MailboxOwner, arg);
                return;
            }
            if (list.Count != 0)
            {
                string text = list[0].Url.ToString();
                RefreshSharingFolderClient.Tracer.TraceDebug <string>(0L, "Using {0} to call BeginRefreshSharingFolder", text);
                ExchangeServiceBinding exchangeServiceBinding = new ExchangeServiceBinding("RefreshSharingFolder", new RemoteCertificateValidationCallback(RefreshSharingFolderClient.CertificateErrorHandler));
                exchangeServiceBinding.Url = text;
                exchangeServiceBinding.RequestServerVersionValue         = new RequestServerVersion();
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
                exchangeServiceBinding.UserAgent     = WellKnownUserAgent.GetEwsNegoAuthUserAgent("RefreshSharingFolder");
                exchangeServiceBinding.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
                exchangeServiceBinding.Authenticator.AdditionalSoapHeaders.Add(new SerializedSecurityContextType
                {
                    UserSid             = securityAccessToken.UserSid,
                    GroupSids           = RefreshSharingFolderClient.SidStringAndAttributesConverter(securityAccessToken.GroupSids),
                    RestrictedGroupSids = RefreshSharingFolderClient.SidStringAndAttributesConverter(securityAccessToken.RestrictedGroupSids),
                    PrimarySmtpAddress  = mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()
                });
                Exception ex = null;
                try
                {
                    exchangeServiceBinding.BeginRefreshSharingFolder(new RefreshSharingFolderType
                    {
                        SharingFolderId = new FolderIdType
                        {
                            Id = id
                        }
                    }, new AsyncCallback(RefreshSharingFolderClient.TraceResponse), exchangeServiceBinding);
                }
                catch (SoapException ex2)
                {
                    ex = ex2;
                }
                catch (WebException ex3)
                {
                    ex = ex3;
                }
                catch (IOException ex4)
                {
                    ex = ex4;
                }
                catch (InvalidOperationException ex5)
                {
                    ex = ex5;
                }
                catch (LocalizedException ex6)
                {
                    ex = ex6;
                }
                if (ex != null)
                {
                    RefreshSharingFolderClient.Tracer.TraceError <StoreId, IExchangePrincipal, Exception>(0L, "Unable to sync sharing folder {0} in mailbox {1}. Exception {2}", folderId, mailboxSession.MailboxOwner, ex);
                }
                return;
            }
            RefreshSharingFolderClient.Tracer.TraceError <IExchangePrincipal>(0L, "Unable to find internal URL for EWS for mailbox {0}", mailboxSession.MailboxOwner);
        }