MS Azure - 错误请求400

时间:2015-01-25 01:48:13

标签: c# azure azure-mobile-services bad-request

每次运行这行代码时,我都会收到错误的请求错误:

List<Account> accounts = await App.accountTable.Where(account => account.EmailAddress == email).ToListAsync();

以下是错误消息:

A first chance exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.dll
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed.  (Bad Request)
   at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<ThrowInvalidResponse>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<SendRequestAsync>d__1d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<RequestAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<ReadAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<ReadAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.WindowsAzure.MobileServices.Query.MobileServiceTableQueryProvider.<Execute>d__8`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.WindowsAzure.MobileServices.Query.MobileServiceTableQueryProvider.<Execute>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery`1.<ToListAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at eventsphere.Utilities.ValidationUtility.<CheckEmailExistsError>d__2.MoveNext()

然而,我有另一条基本相同的线,它工作正常:

List<Account> accounts = await App.accountTable.Where(account => account.Username == username).ToListAsync();

对于为什么一行会给我一个错误而另一行不会发生错误,我真的很无能为力,因为所有改变的都是我正在查询的Account表的属性。

帐户表格结构:(不会让我发布图片,因为我没有足够的声誉)

CREATE TABLE [eventsphere].[Accounts] (
    [Id]           NVARCHAR (128)     DEFAULT (newid()) NOT NULL,
    [AccountId]    INT                IDENTITY (1, 1) NOT NULL,
    [Username]     NVARCHAR (MAX)     NULL,
    [EmailAddress] NVARCHAR (MAX)     NULL,
    [Password]     NVARCHAR (MAX)     NULL,
    [IsBusiness]   BIT                NOT NULL,
    [User_Id]      NVARCHAR (128)     NULL,
    [Business_Id]  NVARCHAR (128)     NULL,
    [Version]      ROWVERSION         NOT NULL,
    [CreatedAt]    DATETIMEOFFSET (7) DEFAULT (sysutcdatetime()) NOT NULL,
    [UpdatedAt]    DATETIMEOFFSET (7) NULL,
    [Deleted]      BIT                NOT NULL,
    CONSTRAINT [PK_eventsphere.Accounts] PRIMARY KEY NONCLUSTERED ([Id] ASC),
    CONSTRAINT [FK_eventsphere.Accounts_eventsphere.Businesses_Business_Id] FOREIGN KEY ([Business_Id]) REFERENCES [eventsphere].[Businesses] ([Id]),
    CONSTRAINT [FK_eventsphere.Accounts_eventsphere.Users_User_Id] FOREIGN KEY ([User_Id]) REFERENCES [eventsphere].[Users] ([Id])
);

任何输入都将不胜感激!在此先感谢:)

2 个答案:

答案 0 :(得分:0)

(在我有10个声望之前无法发表评论,因此我将此作为答案发布..)

以下是生成并发送到我们数据库的本地副本的查询请求:

http://localhost:59737/tables/Account?$filter=(emailaddress%20eq%20%27email%40test.com%27)    

返回此对象(我认为“message”属性非常重要):

{"message":"The query specified in the URI is not valid. Could not find a property named 'emailaddress' on type 'eventsphereService.DataObjects.Account'.","exceptionMessage":"Could not find a property named 'emailaddress' on type 'eventsphereService.DataObjects.Account'.","exceptionType":"Microsoft.Data.OData.ODataException","stackTrace":"   at Microsoft.Data.OData.Query.EndPathBinder.GeneratePropertyAccessQueryForOpenType(EndPathToken endPathToken, SingleValueNode parentNode)\r\n   at Microsoft.Data.OData.Query.EndPathBinder.BindEndPath(EndPathToken endPathToken, BindingState state)\r\n   at Microsoft.Data.OData.Query.MetadataBinder.BindEndPath(EndPathToken endPathToken)\r\n   at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n   at Microsoft.Data.OData.Query.BinaryOperatorBinder.GetOperandFromToken(BinaryOperatorKind operatorKind, QueryToken queryToken)\r\n   at Microsoft.Data.OData.Query.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n   at Microsoft.Data.OData.Query.MetadataBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n   at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n   at Microsoft.Data.OData.Query.FilterBinder.BindFilter(QueryToken filter)\r\n   at Microsoft.Data.OData.Query.ODataUriParser.ParseFilterImplementation(String filter, IEdmType elementType, IEdmEntitySet entitySet)\r\n   at System.Web.Http.OData.Query.FilterQueryOption.get_FilterClause()\r\n   at System.Web.Http.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n   at System.Web.Http.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n   at System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n   at System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n   at System.Web.Http.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n   at System.Web.Http.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n   at System.Web.Http.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"}

然而,当我们在浏览器中修改时,如下所示:

http://localhost:59737/tables/Account?$filter=(EmailAddress%20eq%20%27email%40test.com%27)

它会返回一些数据。

查询用户名字段时,“用户名”和“用户名”都会返回数据。

Account DataObject定义为:

public class Account : EntityData
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int AccountId { get; set; }
    public string Username { get; set; }
    [DataType(DataType.EmailAddress)]
    public string EmailAddress { get; set; }
    public string Password { get; set; }
    public bool IsBusiness { get; set; }

    public string User_Id { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    [ForeignKey("User_Id")]
    [Association("UserIdAssociation", "UserId", "Id")]
    [Column(Order = 1)]
    public virtual User User { get; set; }

    public string Business_Id { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    [ForeignKey("Business_Id")]
    [Association("BusinessIdAssociation", "BusinessId", "Id")]
    public virtual Business Business { get; set; }
}

答案 1 :(得分:0)

您的客户端EmailAddress属性是什么样的?它在某些时候变得越来越低 - 你的客户端模型中是否有任何属性?

“用户名”和“用户名”都起作用的原因是服务器允许大写和小写的第一个字母。例如,'emailAddress'应该有效。