0

我是新來的移動應用服務和天青,我想讓應用服務層工作,然後將其移植到Xamarin應用,所以我想我只是嘗試一個簡單的WPF應用程序使用該服務。來自wpf應用的azure移動應用服務的問題

我下載了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; } 
    } 

} 

應用服務 的TodoItem

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 
+0

你是如何使用WPF應用程序中的服務的?我真的無法使WPF應用程序中的移動應用程序工作。您是如何創建項目的,您是否必須創建.net標準類庫? – WiteCastle

回答

0

我會倒帶並辦理政黨成員里亞爾再次。你做錯了什麼,並沒有提供足夠的信息來說明究竟是什麼。顯然,你沒有包含實際執行查詢的代碼。

+0

我很確定TodoController.cs代碼是正確的,這是查詢完成的地方。這是一個關於它的快速討論。 http://stackoverflow.com/questions/41091994/what-is-the-tablecontroller-class-for-and-where-are-its-methods-used –

+0

查詢部分在服務器上完成,部分在客戶端完成。我在團隊中工作,並且熟悉客戶端和服務器代碼庫。 –

+0

感謝您的幫助。我仍然有點困惑如何從數據庫返回所有待辦事項。希望你能幫助清理它。在Azure門戶中,我做了移動快速入門,並下載了TodoItem教程的.net後端。上面是TodoController,你是說我需要額外的代碼嗎?我認爲client.GetTable 。()。ToListAsync();會調用public IQueryable GetAllTodoItems(),因爲它的方法名以GetAll開頭? 如果這是不正確的,你能幫我理解從db返回所有todo項目所需的基本代碼嗎? –

相關問題