簡體   English   中英

在Azure輔助角色http請求中獲取http 500

[英]Get http 500 in a Azure worker role http request

我有一個運行1個工作角色和1個Web角色的Azure Web服務,這些角色設置為處於Azure專用網絡中。

worker角色與我們的數據庫執行一些同步工作,該數據庫正在從許多API和服務器下載報告文件,然后將其同步到我們的數據庫,出於某種原因(10個中的1個)API http請求在雲中返回HTTP錯誤500,但是當我在機器上對其進行調試時,它可以正常工作,並且我在EC2(AWS)aspx網站上運行的代碼與在AWS上運行的數據庫所做的相同,這很好。

這是執行該任務的代碼(失敗的代碼):

public void GenerateReport(DateTime start, DateTime end)
        {
            string URL = this._cj_url;
            URL = string.Format(URL, start.ToString("yyyy-MM-dd"), end.ToString("yyyy-MM-dd"));
            RequestState myRequestState = new RequestState();
            myRequestState.request = (HttpWebRequest)WebRequest.Create(URL);
            myRequestState.from = start;
            myRequestState.to = end;
            myRequestState.prefix = "CJ";
            myRequestState.ext = "xml";

            try
            {
                myRequestState.request.Headers.Add("authorization:" + _devKey);
                myRequestState.request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1";

                HttpWebRequest myHttpWebRequest = myRequestState.request;
                myRequestState.response = (HttpWebResponse)myHttpWebRequest.GetResponse();

                // Read the response into a Stream object.
                Stream responseStream = myRequestState.response.GetResponseStream();
                myRequestState.streamResponse = responseStream;

                //' Get response  
                myRequestState.response = (HttpWebResponse)myRequestState.request.GetResponse();


                //' Get the response stream into a reader  
                StreamReader reader = new StreamReader(myRequestState.response.GetResponseStream());
                this.allFileRows = reader.ReadToEnd();

            }
            catch (Exception e1)
            {
                this.monitor.PushToErrors("CJ - error in downloading the file - " , e1,true);
            }

        }

這是RequestState類:

public class RequestState
    {
        // This class stores the State of the request.
        const int BUFFER_SIZE = 1024;
        public StringBuilder requestData;
        public byte[] BufferRead;
        public HttpWebRequest request;
        public HttpWebResponse response;
        public Stream streamResponse;
        public DateTime from;
        public DateTime to;
        public string prefix;
        public string ext;

        public RequestState()
        {
            BufferRead = new byte[BUFFER_SIZE];
            requestData = new StringBuilder("");
            request = null;
            streamResponse = null;
        }
    }

這是請求調用的網址:

this._cj_url = "https://commission-detail.api.cj.com/v3/commissions?date-type=posting&start-date={0}&end-date={1}";

編輯:

由於某種原因,我在對服務實例啟用了遠程控制后,它得到了修復。 我真的很想知道我怎么會遇到這個問題...

一種想法是,當您在雲中運行代碼時,您正在它們的服務器上運行,這意味着您的日期可能全都不用了。 在您假設DateTime.Now (或您正在做的任何事情)是您的時間之前,我已經看過了它,但實際上它是您在雲中運行的VM的服務器時間。 可能是日期問題的原因是,我看到您正在將日期參數傳遞給URL,也許在雲中運行時它們的格式設置錯誤?

暫無
暫無

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

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