【问题标题】:Azure WebJobs PingException, .exe runs fine as a console applicationAzure WebJobs PingException,.exe 作为控制台应用程序运行良好
【发布时间】:2016-02-03 09:25:49
【问题描述】:

我正在尝试构建一个 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 异常?

【问题讨论】:

    标签: c# azure


    【解决方案1】:
    ---> System.ComponentModel.Win32Exception: There are no more endpoints available from the endpoint mapper
    

    从这一行来看,您的应用程序正在访问您计算机上存在但在 Azure Web App Worker 上不可用的东西,或者是在 Worker 上运行的沙盒的受限调用。

    您可以查看有关Sandbox that runs on the App Service Workers here 的更多信息。

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

    网络限制/注意事项

    从网络访问方面存在多种限制 Azure Web 应用程序。本部分概述了特定于 Azure 应用的限制 服务;此外,应用程序仍然受制于 Azure 自己的 网络限制。

    网络端点监听

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

    【讨论】:

    • 这很糟糕,但确实解释了为什么 ping 不起作用。谢谢。
    • 也有类似的问题。在本地一切正常,但在 azure 上失败。所有请求/响应都使用 80/443 端口发送。很奇怪。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2021-03-24
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多