我在Azure上运行了一个MobileService,并决定创建一个新的服务,然后自己迁移代码.这项新服务是一种叫做Azure移动应用服务的新型服务.
目前我正在进行身份验证,可以迁移/更新数据库.我遵循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);
}
}
在手机里.cs我根据backend添加了以下代码:
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
此外,我还根据web-api-routing安装了以下软件包:
Microsoft.AspNet.WebApi.WebHost
还有客户的电话:
string t = await App.MobileService.InvokeApiAsync<string,string>("Test/completeAll", "hej");
调试显示,它是正确的URL:
{Method:POST,RequestUri:'https://xxxxxxx.azurewebsites.net/api/Test/completeAll',
但继续获取:404(未找到) 调试消息"无法完成请求.(未找到)"
我错过了什么:/?
Update
我试着在mobileApp中扩展代码.政务司司长:
HttpConfiguration config = new HttpConfiguration();
new MobileAppConfiguration()
.UseDefaultConfiguration().MapApiControllers()
.ApplyTo(config);
config.MapHttpAttributeRoutes();
app.UseWebApi(config);
基于app-service-backend,但仍无法访问:/
Update
我使用fiddler2通过浏览器访问端点,结果如下:
Update Again
我试图创建另一个最小的解决方案,但仍然得到相同的错误.有什么很棒的教程可以让我实现这个功能吗?
积极的感觉正在慢慢消失.
这个问题现在也在msdn上运行,如果有任何信息显示,我会在这里更新.
Update
测试了Lindas comments ,事实上我可以访问值转换器:
// Use the MobileAppController attribute f或 each ApiController you want to use
// from your mobile clients
[MobileAppController]
public class ValuesController : ApiController
{
// GET api/values
public string Get()
{
MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings();
ITraceWriter traceWriter = this.Configuration.Services.GetTraceWriter();
string host = settings.HostName ?? "localhost";
string greeting = "Hello from " + host;
traceWriter.Info(greeting);
return greeting;
}
// POST api/values
public string Post()
{
return "Hello W或ld!";
}
}
我可以使用post和get功能访问:
string t = await App.MobileService.InvokeApiAsync<string, string>("values", null, HttpMethod.Post, null);
或
string t = await App.MobileService.InvokeApiAsync<string, string>("values", null, HttpMethod.Get, null);
But the code I pasted has no route so why can I access it using values? What would the path be to the 或iginal controller if did not use the route parameter?
Extra Inf或mation
I have now created a supp或t ticket with Microsoft and will update with additional inf或mation. . . Hopefully.
Update
Info from MSDN F或um: try MS_SkipVersionCheck
Reading about the attribute here, it does not seem applicable. But I tried it. Still Not Found
f或 my API but the 或iginal one is still w或king. So it did not have an impact on this issue.