簡體   English   中英

C#和AWS S3-盡管僅發出單個請求仍收到ServiceUnavailable錯誤

[英]C# and AWS S3 - receiving ServiceUnavailable error despite only making a single request

AWS外部服務器上的軟件使用以下代碼從Amazon S3存儲桶中的文件中獲取一些信息。 然后,將這些數據分解並用於其他目的。

List<Document> documentList = new List<Document>();
            try
            {
                AmazonS3Config amazonS3Config = new AmazonS3Config();
                amazonS3Config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(Settings.AWSRegion);

                if (Settings.Proxy == true)
                {
                    if (Settings.IsMasterService == true)
                    {
                        amazonS3Config.ProxyHost = Settings.ProxyHost;
                        amazonS3Config.ProxyPort = Settings.ProxyPort;
                        amazonS3Config.ProxyCredentials = System.Net.CredentialCache.DefaultCredentials;
                    }
                    else
                    {
                        if (Settings.IsCompanyStore == true)
                        {
                            amazonS3Config.ProxyHost = Settings.ProxyHostCompanyStore;
                            amazonS3Config.ProxyPort = Settings.ProxyPortCompanyStore;

                            NetworkCredential corpProxyCreds = new NetworkCredential(Settings.ProxyUserNameCompanyStore, Settings.ProxyPasswordCompanyStore);
                            amazonS3Config.ProxyCredentials = corpProxyCreds;
                        }
                    }
                }
                AmazonS3Client s3 = new AmazonS3Client(amazonCreds, amazonS3Config);

                GetObjectRequest req = new GetObjectRequest();
                req.BucketName = Settings.S3BucketName;
                req.Key = Settings.S3ObjectName;
                using (GetObjectResponse response = s3.GetObject(req))
                    if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
                    {
                        using (Stream amazonStream = response.ResponseStream)
                        {
                            StreamReader amazonStreamReader = new StreamReader(amazonStream);
                            string _lne = string.Empty;
                            while ((_lne = amazonStreamReader.ReadLine()) != null)
                            {
                                string[] _cfglines = _lne.Split('&');
                                foreach (string c in _cfglines)
                                {
                                    string[] _fle = c.Split('|');
                                    Document d = new Document();
                                    d.Name = _fle[1];
                                    d.FolderPath = _fle[0];

                                    documentList.Add(d);
                                }
                            }
                        }
                    }
                    else
                    {
                        EventHandling.RaiseDebugEvent("response.HttpStatusCode.ToString() = " + response.HttpStatusCode.ToString());
                        throw new Exception("Could not obtain master configuration file. Status: " + response.HttpStatusCode.ToString());
                    }
            }
            catch (Exception ex)
            {
                EventHandling.RaiseDebugEvent(" ReturnCloudCaptureDocumentList ex.tostring = " + ex.ToString());
                EventHandling.RaiseEvent(ex.Message, System.Diagnostics.EventLogEntryType.Error);
            }

            return documentList;

在AWS之外,我們有兩種不同類型的服務器。 一個在代理之后,一個不在代理之后。

在不位於代理后面的服務器上,此代碼可以正常工作。 在Web代理后面的服務器上,此代碼每次都會失敗,並顯示以下錯誤:

'使用錯誤代碼ServiceUnavailable和Http Status Code ServiceUnavailable發出錯誤請求。 該服務未返回其他錯誤信息。

查看Amazon文檔,當您在短時間內向S3提出過多請求時,將發生ServiceUnavailable錯誤。 但是,這種情況並非如此。 我們僅發出一個請求,即使我們發出許多請求,也無法解釋為什么在一台服務器上它可以正常工作,而在另一台服務器上卻不能工作(唯一的區別是存在代理)。

任何意見,將不勝感激。

(好吧,如果沒有其他人想要這個聲譽,我會接受。;)

我至少可以想到三件事(@ Collin-Dauphinee的ht)。

  1. 對存儲桶的訪問可能僅限於非代理計算機的IP。
  2. 您的代理人可能正在處理該請求。
  3. 您的代理人可能拒絕轉發請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM