运行 控制台中的 webjob 工作但在 Azure 上抛出异常:无法解析远程名称:'xxx.queue.core.windows.net'

Running webjob in console works but throws exception on Azure: The remote name could not be resolved: 'xxx.queue.core.windows.net'

我的网络作业从我的 blob 存储中删除了文档。如果我将代码复制到控制台应用程序并 运行 它,它将 运行 无误地完成。如果我在 visual studio 中创建一个新的 webjob(右键单击我的网站项目并 select 添加 -> 新建 Azure Webjob 项目),将代码复制到 Functions.cs 并部署,Azure 会抛出异常当 运行 网络作业时:

===============================================

[09/09/2016 01:51:44 > fc93a9: ERR ] Unhandled Exception: Microsoft.WindowsAzure.Storage.StorageException: The remote name could not be resolved: 'xxx.queue.core.windows.net' ---> System.Net.WebException: The remote name could not be resolved: 'xxx.queue.core.windows.net'
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)
[09/09/2016 01:51:44 > fc93a9: ERR ]    --- End of inner exception stack trace ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.EndExists(IAsyncResult asyncResult)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass1`1.<CreateCallback>b__0(IAsyncResult ar)
[09/09/2016 01:51:44 > fc93a9: ERR ] --- End of stack trace from previous location where exception was thrown ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueListener.<ExecuteAsync>d__4.MoveNext()
[09/09/2016 01:51:44 > fc93a9: ERR ] --- End of stack trace from previous location where exception was thrown ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.TaskSeriesTimer.<RunAsync>d__d.MoveNext()
[09/09/2016 01:51:44 > fc93a9: ERR ] --- End of stack trace from previous location where exception was thrown ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.BackgroundExceptionDispatcher.<>c__DisplayClass1.<Throw>b__0()
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ThreadHelper.ThreadStart()
[09/09/2016 01:51:44 > fc93a9: SYS ERR ] Job failed due to exit code -532462766

=======================================================

我没有队列,所以这可能是错误的来源,但奇怪的是我没有尝试访问队列,我只是访问我的 blob 存储。

不确定这是否有帮助,但我的网络作业 Program.cs 看起来像这样:

    static void Main()
    {
        JobHostConfiguration config = new JobHostConfiguration();
        config.Tracing.ConsoleLevel = TraceLevel.Verbose;

        config.UseTimers();

        var host = new JobHost(config);
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }

这是作业中唯一使用存储的代码,其余的是用于获取列表等的数据库内容。

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("agentdocuments");

foreach (var doc in expiredDocs)
{
    if (doc.ContentLength == 1)
    {
        // Retrieve reference to blob
        CloudBlockBlob blockBlob = container.GetBlockBlobReference($"{doc.SubDomain.ToLower()}/{doc.ClientId}/{doc.FileId}");

        await blockBlob.DeleteIfExistsAsync();
    }
}

编辑:我还应该补充一点,这只是在更新后才开始发生:

还有一些代码更改和其他更新(如 Newtonsoft.Json、Microsoft.WindowsAzure.ConfigurationManager、Microsoft.Web.WebJobs.Publish),但我访问 blob 的方式没有代码更改。

更新 - 我的网络作业 运行 在周末完成。它在 22:23 失败并出现与上述相同的错误,但随后 运行 在 22:24 重试时成功。但是今天又因为同样的错误再次失败。我将按照@FleminAdambukulam 的说明尝试删除日志记录,但 st运行ge 如何在没有任何代码更改的情况下 运行 但随后再次失败......

问题是存储帐户是只支持 Blob 的特殊类型。即使您没有使用队列,WebJobs SDK 在内部也依赖于它们。因此,为了使用 WebJobs SDK,您需要使用常规存储帐户。