Search code examples
asp.net-web-apixamarin.formsazure-mobile-servicesmobileserviceclient

Azure Mobile Service Client InvokeApiAsync not hitting WebAPI


I can't seem to hit my web api from my xamarin forms mobile app. I can hit the api via PostMan and it works fine.

A command that runs when text is entered

return _searchCommand ?? (_searchCommand = new Command<string>(async (text) => await ExecutSearchCommand(text)));

This command calls my ExecuteSearchCommand method in which my client makes my api call

async Task ExecuteSearchCommand(string search){
    var table = await App.Client.InvokeApiAsync("api/Item", System.Net.Http.HttpMethod.Get, new Dictionary<string, string> (){ { "filter", search } });
    ...
}

My ItemController looks like this

[MobileAppController]
[Route("api/Item")]
public class ItemController : ApiController
{
    [HttpGet]
    public async Task<IEnumerable<Item>> Get(string filter)
    {
        return await itemRepository.SearchAsync(filter);
    }
}

Is there something I am missing here? I've tried hitting the web api while running locally and pointing my client to localhost as well as to my hosted web api.

*I do have internet permissions set for the android project


Solution

  • The issue was this line

    var table = await App.Client.InvokeApiAsync("api/Item", System.Net.Http.HttpMethod.Get, new Dictionary<string, string> (){ { "filter", search } });
    

    Apparently, it already adds the 'api' prefix when using the InvokeApiAsync method. Removing this fixed the issue.