【发布时间】:2018-05-01 05:59:50
【问题描述】:
我采用了 Windows 服务,将其修改为控制台应用程序,然后将其发布为 WebJob。当它执行 PostAsync 命令时,它没有得到响应,并且不会在 PostAsync 命令之后立即执行 Console.WriteLine。
代码如下:
Console.WriteLine("Querying for access credentials...");
HttpResponseMessage responsePut = null;
try
{
Console.WriteLine("PostAsync call");
responsePut = await client.PostAsync("/oauth/access_token", new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded"));
Console.WriteLine("Returned from PostAsync call");
}
catch (System.Net.Http.HttpRequestException err)
{
Console.WriteLine("Unable to connect to the server (HttpRequestException)..." + err.InnerException);
throw new Exception("Unable to connect to the server (HttpRequestException)..." + err.InnerException);
}
catch (Exception err)
{
Console.WriteLine("Unable to connect to the server (Exception)..." + err.Message + "::" + err.InnerException);
throw new Exception("Unable to connect to the server (Exception)..." + err.InnerException);
}
Azure 控制台日志如下:
[05/01/2018 05:45:31 > e559bd: INFO] Querying for access credentials...
[05/01/2018 05:45:31 > e559bd: INFO] PostAsync call
[05/01/2018 05:45:32 > e559bd: SYS INFO] Status changed to Success
[05/01/2018 05:45:32 > e559bd: SYS INFO] Process went down, waiting for 60 seconds
此代码可用作 Windows 服务和 Windows 控制台应用程序,但在 Azure 上失败。
我可以做些什么来确定 Azure 对我做了什么和/或建议以不同的方式做这件事。
【问题讨论】:
-
尝试在github.com/projectkudu/kudu/wiki/Kudu-console 上运行相同的控制台应用程序。看看它是否提供了更多线索。
-
您可以远程debug it with VS获取更多信息。
-
参见this page,它扩展了 Suwat 的建议。基本上,第一步是让 WebJobs 脱离等式并将其降到尽可能小的重现。
标签: azure azure-webjobs