2016-05-15 46 views
1

我使用Azure的默认服务器(.net)和默认(uwp)应用程序来测试移动应用程序系统。Azure移动应用程序:请求无法完成。 (Bad Request)

发布服务器并通过应用程序连接到服务器后,我收到消息“请求无法完成(错误请求)”。我没有修改任何东西。这是从Azure门户下载的默认项目。

的回应是:
{的StatusCode:400,ReasonPhrase: '错误的请求',版本:1.1,内容:System.Net.Http.StreamContent,头: { 服务器:Microsoft-IIS/10.0 日期:孙年,2016年5月15日18点22分48秒GMT X供电,通过:ASP.NET X-谟服务器版本:净1.1.157.1 的Content-Length:228 内容类型:应用程序/ JSON;字符集= UTF-8 }}

客户做项目:

public class TodoItem 
{ 
    public string Id { get; set; } 

    [JsonProperty(PropertyName = "text")] 
    public string Text { get; set; } 

    [JsonProperty(PropertyName = "complete")] 
    public bool Complete { get; set; } 
} 

客户端逻辑:

private async void ButtonSave_Click(object sender, RoutedEventArgs e) 
    { 
     var todoItem = new TodoItem { Text = TextInput.Text }; 
     TextInput.Text = ""; 
     await InsertTodoItem(todoItem); 
    } 

    private async Task InsertTodoItem(TodoItem todoItem) 
    { 
     // This code inserts a new TodoItem into the database. When the operation completes 
     // and Mobile Apps has assigned an Id, the item is added to the CollectionView 
     await todoTable.InsertAsync(todoItem); 
     items.Add(todoItem); 

     //await App.MobileService.SyncContext.PushAsync(); // offline sync 
    } 

我能做些什么来运行连接/系统?

感谢

+0

有同样的问题。真的很困惑。以前工作得很好。突然我得到这个错误。我浏览了所有文档,其中一些表明我有权限问题(后端应用程序无法在数据库中生成表)。 –

回答

4

我发现,每当我做了以下的一个我得到这个错误:

  • 当客户端或服务器的数据模型不匹配的数据库,无论是客户端还是服务器应用程序没有更改数据库表的权限。在这种情况下,您必须在SQL Server Management Studio中手动删除所有数据库表,然后运行客户端以重新生成包含数据模型中最新更改的表。或者你必须申请迁移。

  • 当您从客户端向表中插入数据并且该表具有外键列并且您为外键列提供值而外键表尚无值时。

例如:

var todoItem= new TodoItem 
{ 
    Name = "Buying some food", 
    UserId = "1" // this will cause the same error if the user table is empty 
}; 

当您尝试插入这个项目,这将导致同样的错误,如果用户表是空

+1

这帮了我。尝试将项目提交给不存在相关项目的表格会失败。 – xerotolerant

+2

对于前者的各种情况,您可以找到在例外情况下深埋6(!)层的违规字段/列名。 http://i.imgur.com/6zISoyZ.png该屏幕截图来自移动应用发送的参数,该参数不在该对象的服务器版本中。如果你在两个对象上都有东西,但不在数据库中,它就非常相似;但我只有一个1级阵列,并且缺少所有参数。 –