远程服务器返回错误:(400)尝试执行AddMessageAsync()

时间:2017-10-10 13:00:26

标签: c# azure queue azure-storage azure-webjobs

我在尝试从另一个项目在Webjob中插入消息时遇到Azure Web作业的问题。在github问题上找不到多少帮助。对于什么是错误感到困惑。我的代码如下:

var queueClient = _storageAccount.CreateCloudQueueClient();
        var queue = queueClient.GetQueueReference("SendReminderEmail");
        var aClassObject = new AModel()
        {
            ObjectName1 = p1,
            ObjectName2 = p2
        };
        var message= new CloudQueueMessage(JsonConvert.SerializeObject(aClassObject ));
        **await queue.AddMessageAsync(message);** error triggers here

消息的json输出:

  

{ “stringKey”: “VALUE1”, “intKey”:}的intValue

这是队列对象的样子: enter image description here

这是我正在使用的堆栈跟踪:

  

错误:{“消息”:“发生错误。”,“ExceptionMessage”:“   远程服务器返回错误:(400)错误   请求 “” ExceptionType。 “:” Microsoft.WindowsAzure.Storage.StorageException “ ”堆栈跟踪“:”   在   Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync [T](IAsyncResult的   结果)在c:\ Program Files中   (86)\詹金斯\工作空间\ release_dotnet_master \ LIB \ ClassLibraryCommon \核心\执行人\ Executor.cs:线   50 \ r \ n at   Microsoft.WindowsAzure.Storage.Queue.CloudQueue.EndAddMessage(IAsyncResult的   c:\ Program Files中的asyncResult)   (86)\詹金斯\工作空间\ release_dotnet_master \ LIB \ ClassLibraryCommon \队列\ CloudQueue.cs:线   1370 \ r \ n at   Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions&LT;&GT; c__DisplayClass4.b__3(IAsyncResult的   ar)在c:\ Program Files中   (86)\詹金斯\工作空间\ release_dotnet_master \ LIB \ ClassLibraryCommon \核心\的Util \ AsyncExtensions.cs:线   114 \ r \ n ---来自先前位置的堆栈跟踪结束异常   被扔了--- \ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.GetResult()\ r \ n at   WebCruiter.Candidate.Web.Services.AzureQueueService.d__2.MoveNext()   在   d:\项目\ WebCruiterRepo \ Webcruiter \ WeCandidate \ WebCruiter.Candidate.Web \ SERVICES \ AzureQueueService.cs:行   31 \ r \ n ---来自先前位置的堆栈跟踪结束异常   被扔了--- \ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.GetResult()\ r \ n at   WebCruiter.Candidate.Web.Controllers.Api.JobApplicationController.d__45.MoveNext()   在   d:\项目\ WebCruiterRepo \ Webcruiter \ WeCandidate \ WebCruiter.Candidate.Web \控制器\阿比\ JobApplicationController.cs:行   1538 \ r \ n ---从前一个位置开始的堆栈跟踪异常   被扔了--- \ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.GetResult()\ r \ n at   WebCruiter.Candidate.Web.Controllers.Api.JobApplicationController.d__18.MoveNext()   在   d:\项目\ WebCruiterRepo \ Webcruiter \ WeCandidate \ WebCruiter.Candidate.Web \控制器\阿比\ JobApplicationController.cs:行   371 \ r \ n ---来自先前位置的堆栈跟踪结束异常   被扔了--- \ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)\ r \ n at   c:\ Program Files中的System.Threading.Tasks.TaskHelpersExtensions.d__3 1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"The remote server returned an error: (400) Bad Request.","ExceptionType":"System.Net.WebException","StackTrace":"
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException[T](HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase
1 cmd,exception ex)   (86)\詹金斯\工作空间\ release_dotnet_master \ LIB \普通\共享\协议\ HttpResponseParsers.Common.cs:线   50 \ r \ n at   Microsoft.WindowsAzure.Storage.Queue.CloudQueue.b__31(RESTCommand`1   cmd,HttpWebResponse resp,Exception ex,OperationContext ctx)in   c:\ Program Files   (86)\詹金斯\工作空间\ release_dotnet_master \ LIB \ ClassLibraryCommon \队列\ CloudQueue.cs:线   2602 \ r \ n at   Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse [T](IAsyncResult的   getResponseResult)在c:\ Program Files中   (86)\詹金斯\工作空间\ release_dotnet_master \ LIB \ ClassLibraryCommon \核心\执行人\ Executor.cs:线   299" }}

1 个答案:

答案 0 :(得分:1)

基本上问题在于您使用的队列名称(SendReminderEmail)。它应全部为小写(sendreminderemail)。有关队列命名规则的完整列表,请参阅以下链接:https://docs.microsoft.com/en-us/rest/api/storageservices/naming-queues-and-metadata

此外,我是否可以建议您通过将消息转换为base64编码的字符串来存储消息。我这说的原因是因为消息体应该是XML安全的。如果您的邮件正文包含<>&等无效字符,则您的邮件将不会添加到队列中。