使用C#后端注册Azure移动服务Custom API

时间:2014-12-03 13:56:01

标签: azure-mobile-services

我使用C#创建了一个自定义API。我从Azure-Portal下载的基础项目。当我使用新的自定义API发布项目时,我可以看到所有“todoItem”函数,但不能看到我创建的自定义API。我如何注册此API?

控制器:

using System;
using System.Threading.Tasks;
using System.Web.Http;
using CustomeeMobileServiceService.DataObjects;
using CustomeeMobileServiceService.Models;
using Microsoft.WindowsAzure.Mobile.Service;

namespace CustomeeMobileServiceService.Controllers
{
    public class MobileRegistrationController : ApiController
    {
        public ApiServices Services { get; set; }

        // GET api/MobileRegistration
        public string Get()
        {
            Services.Log.Info("Hello from custom controller!");
            return "Hello";
        }

        [HttpGet]
        public async Task<Guid> GetMobileRegistrationId()
        {

            using (var context = new CustomeeMobileServiceContext())
            {
                // Get the database from the context.


                var db = context.Database;

                var model = new MobileRegistration();

                var mobileRegistrationId = new Guid();
                var spParams = new object[] { mobileRegistrationId };


                await db.ExecuteSqlCommandAsync("EXEC dbo.MobileRegistration.GetMobileRegistrationId", spParams);

                return mobileRegistrationId;
            }

        }

    }
}

数据对象:

public class MobileRegistration : EntityData
    {
        public Guid MobileRegistrationId { get; set; }           
    }

1 个答案:

答案 0 :(得分:1)

现在您提到了Get函数,我可以看到您有两种不同的方法可以解析处理GET请求(get和getMobileRegistrationID)。这将导致解决使用get请求调用哪个方法的问题。

删除Get()函数,你应该没问题。您无意中混淆了我基于方法名称的基于约定的解决方案(以Get = handle GET开头,以Post = handle POST开头)和基于属性的路由。

相关问题