【发布时间】:2011-06-23 23:36:33
【问题描述】:
问题:此控制台应用程序两次调用托管在 Azure 上的长时间运行的网页。我希望它只调用一次。
控制台应用程序失败并捕获异常:底层连接已关闭:接收时发生意外错误。 so question
如果我从 Chrome 调用页面,它会运行一次(如预期的那样)
public class ExtendedWebClient : WebClient
{
public int Timeout { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
if (request != null)
request.Timeout = Timeout;
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
return request;
}
public ExtendedWebClient()
{
Timeout = 1000000; // in ms.. the standard is 100,000
}
}
class Program
{
static void Main(string[] args)
{
var taskUrl = "http://secret.net/SendWeeklyEmails.aspx";
// create a webclient and issue an HTTP get to our url
try
{
using (ExtendedWebClient httpRequest = new ExtendedWebClient())
{
var output = httpRequest.DownloadString(taskUrl);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception was: " + ex.Message);
}
}
}
【问题讨论】:
-
@smarx - 你是怎么找到那个重复的?只是感兴趣
-
你能运行 fiddler 并监控流量看看发生了什么吗?
-
@Pete2k 我用“azure”标签阅读了所有内容,所以我刚刚看到它。 :)
-
我在问题中链接了重复项.. 认为这可能有助于人们在未来进行谷歌搜索,并尝试以不同的方式解决问题。赞赏大家。 Fiddler 没有工作.. Wireshark 给了我一个线索,让我知道 Chrome 可能在 45 秒后保持活动状态。