I need to send and receive an IList to my Web API:
API Method:
public IList<int> GetKeywordIdsFromIds([FromUri]List<int> ids)
{
// this methods retuns null or an IList<int>
return _iKeywordService.GetKeywordIdsFromIKeywordIds(ids);
}
Call method:
public List<int> GetKeywordIdsFromIds(IList<int> iKeywordIds)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(API_BASE_URL);
client.DefaultRequestHeaders.Accept.Clear();
return client.GetAsync(url + iKeywordIds).Result.Content.ReadAsAsync<List<int>>().Result;
}
}
I get the error:
Exception:Thrown: "No MediaTypeFormatter is available to read an object of type 'List`1' from content with media type 'text/html'." (System.Net.Http.UnsupportedMediaTypeException)
EDIT:
I don't know if this helps but I get this from IIS Log File:
2014-03-31 16:11:31 127.0.0.1 GET /api/ikeyword/getkeywordidsfromids/System.Collections.Generic.List`1[System.Int32] - 80 - 127.0.0.1 - 404 0 2 1
EDIT2:
Default route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);