问题:此控制台应用程序调用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);
}
}
}
答案 0 :(得分:1)
简单回答 - 我不相信这个客户端会两次调用该页面!
如果您的呼叫长时间运行且Azure不允许您进行长轮询,那么您将需要重新架构此应用,以便您可以单独调用启动,然后继续监控此“SendWeeklyEmails”任务。您甚至可以使用命令行客户端代码执行此操作,而不是使用Web应用程序。