【问题标题】:Azure Mobile App: The request could not be completed. (Bad Request)Azure 移动应用:无法完成请求。 (错误的请求)
【发布时间】:2016-05-15 18:40:29
【问题描述】:

我正在使用来自 azure 的默认服务器 (.net) 和默认 (uwp) 应用程序来测试移动应用程序系统。

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

回复是:
{StatusCode:400,ReasonPhrase:“错误请求”,版本:1.1,内容:System.Net.Http.StreamContent,标头: { 服务器:Microsoft-IIS/10.0 日期:2016 年 5 月 15 日星期日 18:22:48 GMT X-Powered-By: ASP.NET x-zumo-服务器版本:net-1.1.157.1 内容长度: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
    }

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

谢谢

【问题讨论】:

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

标签: c# azure mobile win-universal-app


【解决方案1】:

我发现每当我执行以下任一操作时都会出现此错误:

  • 当客户端或服务器数据模型与数据库不匹配并且客户端或服务器应用程序都无权更改数据库表时。在这种情况下,您必须在 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
};

当您尝试插入此项目时,如果用户表为空,这将导致相同的错误

【讨论】:

  • 这对我有帮助。尝试将项目提交到具有不存在的相关项目的表失败。
  • 对于前者的各种情况,您可以在异常中找到隐藏在 6(!) 层深处的违规字段/列名称。 i.imgur.com/6zISoyZ.png 该屏幕截图来自移动应用程序发送的参数,该参数不在对象的服务器版本上。如果您在两个对象上都有一些东西但在数据库中没有,那么它非常相似;但我只有一个 1 元素数组向上一级,并且所有缺少的参数都在其中。
猜你喜欢
  • 2015-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 1970-01-01
  • 2020-05-27
  • 1970-01-01
相关资源
最近更新 更多