我正在尝试构建一个Azure WebJob,每5分钟检查一次网站的状态。我将作业构建为一个运行良好的控制台应用程序。运行时,它将查询MySQL数据库中的网站列表,向网站提交HTTP请求,然后在MySQL数据库中记录该请求的状态。就像我说的,从控制台上看,这个很好用。当我将其压缩并添加为网络作业时,我程序中运行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异常吗?
发布于 2016-02-03 01:25:49
---> System.ComponentModel.Win32Exception: There are no more endpoints available from the endpoint mapper从这一行的外观来看,您的应用程序正在访问计算机上存在但在Azure Web App Worker上不可用的东西,或者是运行在工作程序上的Sandbox的受限调用。
您可以查看更多关于在这里运行在上的沙箱的信息。
在上面链接的页面上,可能导致错误的限制之一是,
网络限制/注意事项 从Azure Web应用程序访问网络有多种限制。本节概述了Azure应用程序服务所特有的限制;此外,应用程序仍然受制于Azure自身的网络限制。 网络端点侦听 通过互联网可以访问应用程序的唯一方法是通过已经公开的HTTP ( 80 )和HTTPS ( 443 ) TCP端口;应用程序可能不会监听来自互联网的数据包。但是,应用程序可能会创建一个套接字,该套接字可以侦听沙箱中的连接。例如,同一应用程序中的两个进程可能通过TCP套接字相互通信;从沙箱外部传入的连接尝试(尽管它们位于同一台计算机上)将失败。有关其他详细信息,请参阅下一个主题。
https://stackoverflow.com/questions/35139161
复制相似问题