internal static SecurityToken GetMessagingToken(this TokenProvider tokenProvider, Uri namespaceAddress, string appliesTo, string action, bool bypassCache, TimeSpan timeout)
        {
            SecurityToken securityToken;

            try
            {
                TimeSpan timeSpan = TimeoutHelper.Min(timeout, TokenProviderUtility.MaxGetTokenSyncTimeout);
                securityToken = tokenProvider.EndGetToken(tokenProvider.BeginGetToken(namespaceAddress, appliesTo, action, bypassCache, timeSpan, null, null));
            }
            catch (TimeoutException timeoutException)
            {
                throw;
            }
            catch (TokenProviderException tokenProviderException1)
            {
                TokenProviderException tokenProviderException = tokenProviderException1;
                throw new MessagingException(tokenProviderException.Message, tokenProviderException);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (!Fx.IsFatal(exception))
                {
                    throw new UnauthorizedAccessException(exception.Message, exception);
                }
                throw;
            }
            return(securityToken);
        }
        internal static IAsyncResult BeginGetMessagingToken(this TokenProvider tokenProvider, Uri namespaceAddress, string appliesTo, string action, bool bypassCache, TimeSpan timeout, AsyncCallback callback, object state)
        {
            Exception    exception;
            IAsyncResult asyncResult;

            try
            {
                asyncResult = tokenProvider.BeginGetToken(namespaceAddress, appliesTo, action, bypassCache, timeout, callback, state);
            }
            catch (Exception exception1)
            {
                if (TokenProviderUtility.HandleTokenException(exception1, out exception))
                {
                    throw exception;
                }
                throw;
            }
            return(asyncResult);
        }
        internal static SecurityToken GetToken(this TokenProvider tokenProvider, string appliesTo, string action, bool bypassCache, TimeSpan timeout)
        {
            TimeSpan timeSpan = TimeoutHelper.Min(timeout, TokenProviderUtility.MaxGetTokenSyncTimeout);

            return(tokenProvider.EndGetToken(tokenProvider.BeginGetToken(appliesTo, action, bypassCache, timeSpan, null, null)));
        }