我正在尝试构建一个Azure WebJob,每隔5分钟检查一次网站的状态。我将这项工作建立为一个工作正常的控制台应用程序。当它运行时,它将在MySQL数据库中查询网站列表,向网站提交HTTP请求,然后在MySQL数据库中记录该请求的状态。就像我说的,从控制台,这工作得很好。当我将其压缩并将其添加为Web作业时,运行Ping以获得响应时间的程序部分失败。我运行ping的代码是:
public ArrayList GetStatusList(ArrayList sites)
{
foreach (Website ws in sites)
{
HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(ws.WebsiteUrl);
webRequest.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse) webRequest.GetResponse();
ws.HttpStatus = response.StatusCode.ToString();
Uri uri = new Uri(ws.WebsiteUrl);
Ping pingClass = new Ping();
PingReply pingReply = pingClass.Send(uri.Host);
ws.ResponseTime = pingReply.RoundtripTime;
ws.WebsiteCheckedDateTime = DateTime.Now;
}
以下是Azure WebJob的错误日志:
[02/01/2016 19:33:37 > c91ef2: SYS INFO] Status changed to Stopped
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Status changed to Starting
[02/01/2016 19:33:57 > c91ef2: SYS WARN] 'Always On' doesn't appear to be enabled for this Web App. To ensure your continuous job doesn't stop running when the SCM host is idle for too long, consider enabling 'Always On' in the configuration settings for your Web App. Note: 'Always On' is available only in Basic, Standard and Premium modes.
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Run script 'IsItAlive.exe' with script host - 'WindowsScriptHost'
[02/01/2016 19:33:57 > c91ef2: SYS INFO] Status changed to Running
[02/01/2016 19:33:58 > c91ef2: INFO] Connected to DB, MySQL version : 5.5.45-log
[02/01/2016 19:33:58 > c91ef2: ERR ]
[02/01/2016 19:33:58 > c91ef2: ERR ] Unhandled Exception: System.Net.NetworkInformation.PingException: An exception occurred during a Ping request. ---> System.ComponentModel.Win32Exception: There are no more endpoints available from the endpoint mapper
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.InternalSend(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options, Boolean async)
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(IPAddress address, Int32 timeout, Byte[] buffer, PingOptions options)
[02/01/2016 19:33:58 > c91ef2: ERR ] --- End of inner exception stack trace ---
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(IPAddress address, Int32 timeout, Byte[] buffer, PingOptions options)
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
[02/01/2016 19:33:58 > c91ef2: ERR ] at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress)
[02/01/2016 19:33:58 > c91ef2: ERR ] at IsItAlive.BusinessLogic.GetStatusOfSites.GetStatusList(ArrayList sites)
[02/01/2016 19:33:58 > c91ef2: ERR ] at IsItAlive.Program.Main(String[] args)
[02/01/2016 19:33:58 > c91ef2: SYS ERR ] Job failed due to exit code -532462766
[02/01/2016 19:33:58 > c91ef2: SYS INFO] Process went down, waiting for 60 seconds
[02/01/2016 19:33:58 > c91ef2: SYS INFO] Status changed to PendingRestart
我确信答案就在我面前,但我没有足够的经验来理解错误日志。有人可以帮助我理解为什么我的Ping在作为WebJob而不是作为控制台应用程序运行时导致Ping异常?
答案 0 :(得分:3)
---> System.ComponentModel.Win32Exception: There are no more endpoints available from the endpoint mapper
从该行的外观来看,您的应用程序正在访问您的计算机上存在的某些内容,但在Azure Web App Worker上不可用,或者是在Worker上运行的Sandbox的限制调用。
您可以查看有关Sandbox that runs on the App Service Workers here的更多信息。
在上述链接页面上,可能导致错误的一个限制是,
网络限制/注意事项
在网络访问方面存在多种限制 Azure Web App。本节概述了Azure App特有的限制 服务;此外,应用程序仍然受Azure自己的限制 网络限制。
网络端点监听
通过互联网访问应用程序的唯一方法是 通过已经公开的HTTP(80)和HTTPS(443)TCP端口; 应用程序可能无法在其他端口上侦听来自的数据包 互联网。但是,应用程序可以创建一个可以的套接字 从沙箱中侦听连接。例如,两个 同一app中的进程可以通过TCP相互通信 插座;连接尝试从沙箱外部传入,尽管如此 他们在同一台机器上,会失败。请参阅下一主题 更多细节。