0

I created a custom API using C#. The base project I donwloaded from Azure-Portal. When I publish the project with the new custom API I can see all the "todoItem" functions but not the custom API I created. How can I register this API?

Controller:

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;
            }

        }

    }
}

DataObjects:

public class MobileRegistration : EntityData
    {
        public Guid MobileRegistrationId { get; set; }           
    }
2
  • When you say you can "see" the todo functions but not the custom API, what do you mean? How are you trying to examine the API? also, are you publishing to Azure or do you mean testing locally? Commented Dec 3, 2014 at 15:36
  • I think it's related to the functions names. I created a new ApiController and did not change the name of the default function: Get(), this time I could see this function under this controller. Commented Dec 3, 2014 at 16:24

1 Answer 1

1

Now that you mentioned the Get function, I can see that you have two different methods that would resolve to handle the GET request (get and getMobileRegistrationID). That will cause issues with the resolution of which method to invoke with a get request.

Remove the Get() function and you should be fine. You are mixing, unintentionally I assume, the convention based resolution based on the name of the methods (starts with Get = handle GET, starts with Post = handle POST) and the attribute based routing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.