我有一个在Azure上运行的MobileService,并决定创建一个新服务并自行迁移代码。这项新服务属于名为Azure Mobile App Service的新型服务。Azure自定义控制器/ API .Net后端
目前我有认证工作,并可以做迁移/更新数据库。我遵循TodoItem示例。我现在想创建自己的自定义API,这就容易在MobileService工作,但我不能让它在Azure移动应用工作:/
我按照这两个环节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);
}
}
在mobileApp.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");
调试后,这是正确的网址:
{方法:POST,RequestUri: 'https://xxxxxxx.azurewebsites.net/api/Test/completeAll', 版本:1.1,内容:系统.Net.Http.StringContent,Headers:{X-ZUMO-FEATURES: AT X-ZUMO-INSTALLATION-ID:e9b359df-d15e-4119-a4ad-afe3031d8cd5 X-ZUMO-AUTH: xxxxxxxxxxx Accept:application/json User-代理: ZUMO/2.0 User-Agent:(lang = Managed; os = Windows Store; OS_VERSION = - ;拱=中性;版本= 2.0.31125.0) X-ZUMO -VERSION:ZUMO/2.0(lang = Managed; os = Windows Store; os_version = - ; arch = Neutral; version = 2.0.31125.0) ZUMO-API-VERSION:2.0。 0 Content-Type:application/json;字符集= UTF-8的Content-Length:3}}
但不断收到:404(未找到) 调试信息 “无法完成请求(未找到)”
我是什么失踪 :/ ?
更新
我试图扩大其在一个MobileApp代码。CS,有:
HttpConfiguration config = new HttpConfiguration();
new MobileAppConfiguration()
.UseDefaultConfiguration().MapApiControllers()
.ApplyTo(config);
config.MapHttpAttributeRoutes();
app.UseWebApi(config);
基于app-service-backend,但仍然没有进入:/
更新
我用fiddler2通过浏览器访问端点,得到了以下结果:
再次更新
我试图创建另一个最小的解决方案,但仍然得到相同的错误。有什么伟大的教程,我可以遵循实现这一功能?
积极的感觉正在慢慢蒸发。 。 。
现在问题也在msdn上运行,如果有任何信息显示,我将在此更新。
更新
测试林多斯评论,我其实是可以访问的值转换器:
// Use the MobileAppController attribute for 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 World!";
}
}
使用这两个职位,并得到功能这个我访问:
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);
但我粘贴的代码没有路由,为什么我可以使用值来访问它?如果没有使用路由参数,那么路径对于原始控制器会是什么?
额外信息
我现在已经创建了一个支持票与微软将提供更多的信息更新。 。 。希望。从MSDN论坛
更新 信息:尝试MS_SkipVersionCheck 阅读有关属性here,它似乎并不适用。但我试过了。我的API仍为Not Found
,但原始的仍在工作。所以它对这个问题没有影响。
当您尝试直接使用Fiddler点击端点时,您是否还获得404? –
@ lindydonna-msft我已经更新了这个问题,但是我仍然得到了404。 – JTIM
尝试重建您的解决方案,并且当您发布时,选中“删除目标上的其他文件”。另外,请确保您使用的是最新版本的服务器SDK,当前版本为1.1.157。 https://www.nuget.org/packages/Microsoft.Azure.Mobile.Server/ –