我是移动应用服务和azure的新手,我想让应用服务层运行然后将其移植到Xamarin应用程序,所以我想我会尝试使用简单的wpf应用程序来使用该服务。
我下载了由azure提供的.NET / c#中的示例ToDo服务并将其发布,但是我得到了这些例外并且感到难过。
这是客户端代码,它会抛出Bad Request异常,我尝试过多次调用app服务,例如插入,更新等,但它们都失败了。
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; }
}
Code 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 :(得分:0)
我倒回来再次浏览教程。你做错了什么并没有提供足够的信息来说明究竟是什么。显然,您没有包含实际执行查询的代码。