【问题标题】:Issues with azure mobile app service from wpf applicationwpf 应用程序中的 azure 移动应用服务问题
【发布时间】:2017-03-02 22:38:14
【问题描述】:

我是移动应用服务和 Azure 的新手,我想让应用服务层正常工作,然后将其移植到 Xamarin 应用,所以我想我会尝试一个简单的 wpf 应用程序来使用该服务。

我下载了 azure 提供的 .NET/c# 中的示例 ToDo 服务并发布了它,但是我遇到了这些异常并且被难住了。

这是客户端代码,它抛出了一个错误的请求异常,我尝试了多次调用应用服务,例如插入、更新等,但都失败了。

string url = @"https://mydomain.azurewebsites.net";
MobileServiceClient client = new MobileServiceClient(url);
return await client.GetTable<TodoItem>().ToListAsync();

public class TodoItem
{
    string id;
    string name;
    bool done;

    [JsonProperty(PropertyName = "id")]
    public string Id
    {
        get { return id; }
        set { id = value; }
    }

    [JsonProperty(PropertyName = "text")]
    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    [JsonProperty(PropertyName = "complete")]
    public bool Done
    {
        get { return done; }
        set { done = value; }
    }

}

应用服务 待办事项

public class TodoItem : EntityData
    {
        public string Text { get; set; }

        public bool Complete { get; set; }
    }

代码 TodoController

    // GET tables/TodoItem
    public IQueryable<TodoItem> GetAllTodoItems()
    {
        return Query();
    }

    // GET tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
    public SingleResult<TodoItem> GetTodoItem(string id)
    {
        return Lookup(id);
    }

    // PATCH tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
    public Task<TodoItem> PatchTodoItem(string id, Delta<TodoItem> patch)
    {
        return UpdateAsync(id, patch);
    }

    // POST tables/TodoItem
    public async Task<IHttpActionResult> PostTodoItem(TodoItem item)
    {
        TodoItem current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);
    }

    // DELETE tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
    public Task DeleteTodoItem(string id)
    {
        return DeleteAsync(id);
    }

应用服务日志记录和异常

Method: GET, RequestUri: 'https://mydomain.azurewebsites.net/tables/TodoItem', Version: 1.1, Content: <null>, Headers:
{
  X-ZUMO-FEATURES: TT
  X-ZUMO-INSTALLATION-ID: cd7127a1-efc4-4967-b646-e99a069976cb
  Accept: application/json
  User-Agent: ZUMO/1.3
  User-Agent: (lang=Managed; os=Windows; os_version=6.1.65536.7601; arch=Win32NT; version=1.3.30324.0)
  X-ZUMO-VERSION: ZUMO/1.3 (lang=Managed; os=Windows; os_version=6.1.65536.7601; arch=Win32NT; version=1.3.30324.0)
}}

{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Date: Thu, 02 Mar 2017 02:44:30 GMT
  Set-Cookie: ARRAffinity=1b2631dc149e564d651190bdb0b6895025c984e8ad5bea83fb1e545ec292facb;Path=/;Domain=mydomain.azurewebsites.net
  Server: Microsoft-IIS/8.0
  X-Powered-By: ASP.NET
  Content-Length: 220
  Content-Type: application/json; charset=utf-8
}}

Application: 2017-03-02T03:48:26  PID[6016] Information Request, Method=GET, Url=https://mydomain.azurewebsites.net/tables/TodoItem, Message='https://mydomain.azurewebsites.net/tables/TodoItem'
Application: 2017-03-02T03:48:26  PID[6016] Information Message='TodoItem', Operation=DefaultHttpControllerSelector.SelectController
Application: 2017-03-02T03:48:26  PID[6016] Information Message='mydomainService.Controllers.TodoItemController', Operation=DefaultHttpControllerActivator.Create
Application: 2017-03-02T03:48:26  PID[6016] Information Message='mydomainService.Controllers.TodoItemController', Operation=HttpControllerDescriptor.CreateController
Application: 2017-03-02T03:48:53  PID[6016] Information Message='Selected action 'GetAllTodoItems()'', Operation=ApiControllerActionSelector.SelectAction
Application: 2017-03-02T03:48:53  PID[6016] Information Operation=HttpActionBinding.ExecuteBindingAsync
Application: 2017-03-02T03:48:53  PID[6016] Information Operation=TableQueryFilter.OnActionExecutingAsync
Application: 2017-03-02T03:48:53  PID[6016] Information Operation=EnableQueryAttribute.OnActionExecutingAsync
Application: 2017-03-02T03:48:53  PID[6016] Information Message='Will use same 'JsonMediaTypeFormatter' formatter', Operation=JsonMediaTypeFormatter.GetPerRequestFormatterInstance
Application: 2017-03-02T03:48:53  PID[6016] Information Message='Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
Application: 2017-03-02T03:48:53  PID[6016] Information Operation=TableControllerConfigAttribute.OnActionExecutingAsync, Status=400 (BadRequest)
Application: 2017-03-02T03:48:53  PID[6016] Information Operation=EnableQueryAttribute.OnActionExecutedAsync, Status=400 (BadRequest)
Application: 2017-03-02T03:48:53  PID[6016] Information Operation=TableQueryFilter.OnActionExecutedAsync, Status=400 (BadRequest)
Application: 2017-03-02T03:48:54  PID[6016] Information Operation=TodoItemController.ExecuteAsync, Status=400 (BadRequest)
Application: 2017-03-02T03:48:54  PID[6016] Information Response, Status=400 (BadRequest), Method=GET, Url=https://mydomain.azurewebsites.net/tables/TodoItem?$select=Text,Complete,Id,Version,CreatedAt,UpdatedAt,Deleted, Message='Content-type='application/json; charset=utf-8', content-length=unknown'
Application: 2017-03-02T03:48:54  PID[6016] Information Operation=JsonMediaTypeFormatter.WriteToStreamAsync
Application: 2017-03-02T03:48:55  PID[6016] Information Operation=TodoItemController.Dispose

【问题讨论】:

  • 您是如何在 WPF 应用程序中使用该服务的?我真的很难让移动应用程序在 WPF 应用程序中工作。您是如何创建项目的,您是否必须创建一个 .net 标准类库?

标签: .net azure mobile azure-mobile-services azure-web-app-service


【解决方案1】:

我会倒带并再次浏览教程。你做错了什么,并且没有提供足够的信息来说明究竟是什么。明确地说,您没有包含实际执行查询的代码。

【讨论】:

  • 我很确定 TodoController.cs 代码是正确的,这就是完成查询的地方。这是一个关于它的快速讨论。 stackoverflow.com/questions/41091994/…
  • 查询部分在服务器上完成,部分在客户端上完成。我在团队中工作,并且与客户端和服务器代码库都很亲密。
  • 感谢您的帮助。我仍然对如何从数据库中返回所有待办事项感到有点困惑。希望你能帮助清理它。我从 azure 门户进行了移动快速入门并下载了 TodoItem 教程的 .net 后端。上面是 TodoController,你是说我需要额外的代码吗?我以为 client.GetTable.().ToListAsync();会调用 public IQueryable GetAllTodoItems() 因为它的方法名以 GetAll 开头?如果这不正确,您能帮我理解从数据库返回所有待办事项所需的基本代码吗?
  • 阅读关于这个主题的书 - aka.ms/zumobook - 这将在第 3 章中介绍。
  • 谢谢,我会效仿他们的。我潜在的挫败感是,微软的教程不需要用户像在第 3 章中那样向 todo 服务教程添加额外的代码。微软的文档似乎有问题,或者它是正确的,但还有一个问题.这是此示例的 microsoft 演练的链接,除了使用 xamarin 客户端而不是使用 wpf 客户端。 docs.microsoft.com/en-us/azure/app-service-mobile/…
猜你喜欢
  • 1970-01-01
  • 2015-07-19
  • 1970-01-01
  • 2012-09-04
  • 1970-01-01
  • 1970-01-01
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多