我有一个托管在Azure(PaaS)上的MVC应用程序,并且对于每个传入请求,它都会执行对端点的调用。我有时会遇到以下错误:操作已超时但在端点端(即使我不知道那里发生了什么),他们说他们没有收到这些特定的电话。 我的MVC应用程序在Global.asax文件中设置了以下属性:
ServicePointManager.DefaultConnectionLimit = 64;
为了避免我在每次通话时设置的问题,如下所示:
HttpWebRequest _WebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
_WebRequest.ServicePoint.ConnectionLimit = connectionLimit;
_WebRequest.Proxy = null;
_WebRequest.Timeout = timeout;
_WebRequest.ServicePoint.ConnectionLeaseTimeout = 0;
_WebRequest.CookieContainer = new CookieContainer();
_WebRequest.UserAgent = UserAgent;
_WebRequest.Method = "POST";
_WebRequest.ContentType = contentType;
_WebRequest.KeepAlive = true;
_WebRequest.Accept = "*/*";
_WebRequest.Headers.Add("Accept-Encoding", "gzip, deflate, sdch");
_WebRequest.Headers.Add("Accept-Language", "it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4");
_WebRequest.Headers.Add("Upgrade-Insecure-Requests", "1");
_WebRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
_WebRequest.AllowAutoRedirect = false;
_WebRequest.Referer = referer;
byte[] data = Encoding.ASCII.GetBytes(body);
_WebRequest.ContentLength = data.Length;
using (Stream requestStream = _WebRequest.GetRequestStream()) {
requestStream.Write(data, 0, data.Length);
}
using (WebResponse _webResponse = (HttpWebResponse)_WebRequest.GetResponse()) {
using (Stream dataStream = _webResponse.GetResponseStream()) {
using (StreamReader reader = new StreamReader(dataStream)){
response = reader.ReadToEnd();
}}
我还为我的应用程序启用了Azure端的应用程序洞察,但除了超时之外我无法获得任何特定错误
我也尝试将我的超时设置为一个非常短的值,然后在调用错误后重试:在这种情况下,第二次调用很好,所以我想知道为什么第一次调用有时会失败