示例#1
0
            private string _UpdateToken(NetworkCredential credentials)
            {
                Debug.Assert(credentials != null);

                string tokenString;

                try
                {
                    // Get token from token service.
                    Token token;
                    switch (TokenType)
                    {
                    case Services.TokenType.Default:
                        token = AgsHelper.GetServerToken(_tokenServiceUrl, credentials);
                        break;

                    case Services.TokenType.Arcgis_com:
                        token = AgsHelper.GetServerTokenUsingReferer(_tokenServiceUrl, credentials);
                        break;

                    default:
                        // New token type was added.
                        Debug.Assert(false);

                        token = AgsHelper.GetServerToken(_tokenServiceUrl, credentials);
                        break;
                    }

                    lock (_tokenLocker)
                    {
                        _lastToken      = token.Value;
                        _expirationTime = token.Expires;

                        tokenString = _lastToken;
                    }
                }
                catch (WebException e)
                {
                    // TODO: Server returns "Forbidden" status on incorrect username/password,
                    // but it's too ambiguous status, we need more specific info to determine
                    // if the error is related to authentication problem

                    // HTTP_STATUS_FORBIDDEN (403): The server understood
                    // the request, but cannot fulfill it.
                    if (e.Response != null &&
                        ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Forbidden)
                    {
                        throw new AuthenticationException();
                    }
                    else
                    {
                        throw;
                    }
                }

                return(tokenString);
            }
示例#2
0
        private string _MakeServiceUrl()
        {
            Debug.Assert(_baseUrl != null);
            Debug.Assert(_connection != null);

            string url = _baseUrl;

            if (_connection.RequiresTokens)
            {
                url = AgsHelper.FormatTokenUrl(url, _connection.LastToken);
            }

            return(url);
        }