Azure WebJobs PingException,.exe作为控制台应用程序运行良好

本文关键字:应用程序 控制台 运行 WebJobs PingException exe Azure | 更新日期: 2023-09-27 18:32:51

我正在尝试构建一个 Azure Web Job 以每 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 Web 作业的错误日志:

[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 在作为 Web 作业而不是控制台应用程序运行时会导致 Ping 异常吗?

Azure WebJobs PingException,.exe作为控制台应用程序运行良好

---> System.ComponentModel.Win32Exception: There are no more endpoints available from the endpoint mapper

从此行的外观来看,应用程序正在访问计算机上存在但在 Azure Web 应用辅助角色上不可用的内容,或者是辅助角色上运行的沙盒的受限调用。

可在此处查看有关在应用服务辅助角色上运行的沙盒的详细信息。

在上面的链接页面上,可能导致错误的限制之一是,

网络限制/注意事项

从 Azure Web App.本部分概述了特定于 Azure 应用的限制 服务;此外,应用程序仍受 Azure 自己的约束 网络限制。

网络终结点侦听

通过互联网访问应用程序的唯一方法是 通过已经暴露的HTTP(80(和HTTPS(443(TCP端口; 应用程序可能不会侦听其他端口上传入的数据包 互联网。 但是,应用程序可能会创建一个套接字,该套接字可以 侦听来自沙盒中的连接。例如,两个 同一应用中的进程可以通过 TCP 相互通信 插座;来自沙盒外部的连接尝试,尽管 它们在同一台计算机上,将失败。请参阅下一主题 其他详细信息。