我在Azure上运行了一个MobileService,并决定创建一个新服务并自己迁移代码.新服务属于新类型:Azure Mobile App Service.
目前我有身份验证工作,可以进行迁移/更新数据库.我正在关注TodoItem示例.我现在想要创建自己的自定义API,它可以轻松地在MobileService上运行,但我无法在Azure Mobile App上运行它:/
我已经关注了这两个链接web-Api-routing和app-service-mobile-backend.我现在有以下内容:
我创建了一个新的控制器:
[MobileAppController]
public class TestController : ApiController
{
// GET api/Test
[Route("api/Test/completeAll")]
[HttpPost]
public async Task<ihttpactionresult> completeAll(string info)
{
return Ok(info + info + info);
}
}
Run Code Online (Sandbox Code Playgroud)
在mobileApp.cs中,我根据后端添加了以下代码:
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
Run Code Online (Sandbox Code Playgroud)
另外我根据web-api-routing安装了以下软件包:
Microsoft.AspNet.WebApi.WebHost
Run Code Online (Sandbox Code Playgroud)
和来自客户的电话:
string t = await App.MobileService.InvokeApiAsync<string,string>("Test/completeAll", "hej");
Run Code Online (Sandbox Code Playgroud)
调试显示,它是正确的URL:
{方法:POST,RequestUri:' https ://xxxxxxx.azurewebsites.net/api/Test/completeAll',版本:1.1,内容:System.Net.Http.StringContent,标题:{X-ZUMO-FEATURES:AT X -ZUMO-INSTALLATION-ID:e9b359df-d15e-4119-a4ad-afe3031d8cd5 X-ZUMO-AUTH:xxxxxxxxxxx接受:application/json User-Agent:ZUMO/2.0 User-Agent:(lang = Managed; os = Windows Store; os_version = - ; arch = …
如果我有以下模型结构
public class QuestionItem: EntityData
{
public string Content { get; set; }
public bool IsAnswered { get; set; }
public int NumberOfAnswers
{
//todo: make it computable
get;
set;
}
public UserItem By { get; set; }
public string ById { get; set; }
public string AtLocation { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
&parent实体为
public class UserItem:EntityData
{
public string UserName { get; set; }
public string Gender { get; set; }
public string BaseLocation { get; set; }
public …
Run Code Online (Sandbox Code Playgroud)