/// <summary>
        /// Generates new token to be used for ArcGIS server requests.
        /// </summary>
        /// <returns>New token which can be used for ArcGIS server requests.</returns>
        public string GenerateToken()
        {
            if (!_authenticator.RequiresTokens)
            {
                throw new InvalidOperationException(
                          Properties.Messages.Error_TokenAuthNotSupported);
            }

            string token = null;

            try
            {
                token = _authenticator.GenerateToken(_parameters.Credentials);
            }
            catch (AuthenticationException e)
            {
                throw ServiceHelper.CreateAuthException(_server, e);
            }
            catch (Exception e)
            {
                if (ServiceHelper.IsCommunicationError(e))
                {
                    throw ServiceHelper.CreateCommException(_server, e);
                }

                throw;
            }

            return(token);
        }
Exemple #2
0
        private Exception _ConvertCommException(Exception ex)
        {
            if (ServiceHelper.IsCommunicationError(ex))
            {
                return(ServiceHelper.CreateCommException(_connection.Title, ex));
            }

            return(ex);
        }
Exemple #3
0
        /// <summary>
        /// Translates the specified exception into the more application-specific
        /// one.
        /// </summary>
        /// <param name="exception">The exception to be translated.</param>
        /// <returns>Translated exception or null reference if the exception
        /// cannot be translated.</returns>
        private Exception _TranslateException(Exception exception)
        {
            if (ServiceHelper.IsCommunicationError(exception) ||
                exception is SerializationException)
            {
                return(ServiceHelper.CreateCommException(_serviceTitle, exception));
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Translates the specified exceptions into ones specific for
        /// <see cref="QueryServiceUrl"/> method.
        /// </summary>
        /// <param name="exception">The exception to be translated.</param>
        /// <returns>Translated exception or null if the exception cannot be
        /// translated and the original one should be thrown.</returns>
        private Exception _TranslateExceptions(Exception exception)
        {
            var isCommunicationError =
                exception is FaultException ||
                ServiceHelper.IsCommunicationError(exception);

            if (isCommunicationError)
            {
                return(ServiceHelper.CreateCommException(_serverTitle, exception));
            }

            return(null);
        }
Exemple #5
0
        /// <summary>
        /// Invokes service method that returns a value of type T.
        /// </summary>
        protected T Invoke <T>(ServiceMethod <T> method)
        {
            const int maxRetryCount = 1;
            int       retryCount    = 0;

            while (true)
            {
                var client = _AcquireClient();
                try
                {
                    return(method.Invoke(client));
                }
                catch (Exception e)
                {
                    if (ProxyAuthenticationErrorHandler.HandleError(e))
                    {
                        continue;
                    }

                    var isTokenError = _IsTokenError(e);
                    if (retryCount >= maxRetryCount || !isTokenError)
                    {
                        if (ServiceHelper.IsCommunicationError(e))
                        {
                            throw ServiceHelper.CreateCommException(
                                      _connection.Title,
                                      e);
                        }

                        throw;
                    }

                    if (isTokenError)
                    {
                        _connection.GenerateToken();
                        _CloseClient(client);
                        client = null;
                    }

                    ++retryCount;
                }
                finally
                {
                    _ReleaseClient(client);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Checks if the specified url points to the load balancing service.
        /// </summary>
        /// <param name="serviceUrl">Url to check for service presence.</param>
        /// <returns>true if and only if the <paramref name="serviceUrl"/>
        /// points to the load balancing service.</returns>
        public static bool HasLoadBalanceService(string serviceUrl)
        {
            var hasService = false;

            try
            {
                var metadataUri = new Uri(serviceUrl + "?wsdl");
                var mexClient   = new MetadataExchangeClient(
                    metadataUri,
                    MetadataExchangeClientMode.HttpGet);
                var metadataRetrievalWrapper = new RetriableInvocationWrapper(
                    MAX_RETRY_COUNT,
                    _PrepareForRetry);
                var metaDocs = metadataRetrievalWrapper.Invoke(
                    () => mexClient.GetMetadata());
                var importer  = new WsdlImporter(metaDocs);
                var contracts = importer.ImportAllContracts();
                foreach (var contract in contracts)
                {
                    if (string.Equals(
                            contract.Name,
                            LOAD_BALANCE_SERVICE_CONTRACT_NAME,
                            StringComparison.InvariantCulture))
                    {
                        hasService = true;
                        break;
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                Logger.Warning(e);
            }
            catch (Exception e)
            {
                if (!ServiceHelper.IsCommunicationError(e))
                {
                    throw;
                }

                Logger.Warning(e);
            }

            return(hasService);
        }