【问题标题】:Get http 500 in a Azure worker role http request在 Azure 辅助角色 http 请求中获取 http 500
【发布时间】:2013-06-12 12:08:39
【问题描述】:

我有一个运行 1 个辅助角色和 1 个 Web 角色的 azure Web 服务,这些角色设置在一个 azure 专用网络中。

worker 角色与我们的数据库执行一些同步工作,即从许多 API 和服务器下载报告文件,然后将它们同步到我们的数据库, 由于某种原因,1(共 10 个)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;
        }
    }

这是请求调用的 URL:

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

编辑:

由于某种原因,在我启用对服务实例的远程控制后,它得到了修复。 我真的很想知道我怎么会遇到这个问题...

【问题讨论】:

  • 抛出的错误/异常是什么?
  • 1) 除了代码 500 之外,响应中没有更多详细信息吗? 2)如果两个角色在同一个部署中,不需要网络,可以设置内部接入点。 3) 您是否知道每个角色只有一个实例无法保证您的机器的正常运行时间?
  • 1.那是错误 - 远程服务器返回错误:(500)内部服务器错误。 2.角色需要与该网络上的另一个虚拟机通信,这就是我将它们设置在该网络中的原因。 3. 是的,我知道,他们正在做一个非常简单且规模不大的工作。

标签: c# .net azure httprequest azure-worker-roles


【解决方案1】:

一种想法是,当您在云中运行代码时,您是在他们的服务器上运行,这意味着您的约会可能会不正常。我之前看过它,您认为DateTime.Now(或您正在做的任何事情)是您的时间,但实际上它是您在云中运行的 VM 的服务器时间。可能是日期问题的原因是我看到您正在将日期参数传递给 URL,也许当您在云中运行时它们的格式错误?

【讨论】:

  • 好吧,我考虑过,但是无论服务器时间是多少,该请求的日期范围都不会错...
  • 您可以将 EXACT http 请求详细信息记录到最后一个详细信息并尝试在本地复制吗?
猜你喜欢
  • 1970-01-01
  • 2012-06-11
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 2017-01-21
  • 2011-08-22
  • 2014-11-09
  • 1970-01-01
相关资源
最近更新 更多