简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM