1 つのワーカー ロールと 1 つの Web ロールを実行している Azure Web サービスがあり、これらのロールは Azure プライベート ネットワークに設定されています。
worker ロールは、多くの API とサーバーからレポート ファイルをダウンロードするデータベースとの同期作業を実行し、それらをデータベースに同期します。何らかの理由で (10 個中) 1 個の API http 要求がクラウドで HTTP エラー 500 を返しますが、私のマシンでデバッグすると動作します。また、AWS で実行されているデータベースで同じことを行っている EC2 (AWS) aspx Web サイトで実行されている同じコードがあり、うまく機能しています。
そのタスクを実行するコード (失敗したもの) は次のとおりです。
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}";
編集 :
サービスインスタンスへのリモートコントロールを有効にした後、何らかの理由で修正されました。なぜこのような問題が発生したのか、私は本当に疑問に思っています...