The web api Get methods are giving me 404 error . Here is what i am doing
Web Api routing
config.Routes.MapHttpRoute(
name: "DefaultApi2",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Web Api Controller methods
[HttpGet]
public GameDto GetGameById(int gameId)
{
//My code here
}
[HttpGet]
public List<GameDto> GetUserGames(int userId)
{
//My code here
}
[HttpGet]
[ActionName("GetPublicGames")]
public List<GameDto> GetPublicGames(int requestUserId, int start, int limit)
{
//My code here
}
[HttpPost]
[ActionName("CreateGame")]
public HttpResponseMessage CreateGame(GameDto gameDto)
{
//My code here
}
[HttpPost]
[ActionName("UserRequestToJoin")]
public HttpResponseMessage ProcessGameInvitationRequest(GameInvitationDto gameInvitationDto)
{
//My code here
}
Client code
try
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:59580/");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync("api/Game/GetGameById?gameId=1");
response.EnsureSuccessStatusCode(); // Throw on error code.
var gameDto = await response.Content.ReadAsAsync<GameDto>();
MessageBox.Show(gameDto.Name);
}
catch (Newtonsoft.Json.JsonException jEx)
{
// This exception indicates a problem deserializing the request body.
MessageBox.Show(jEx.Message);
}
catch (HttpRequestException ex)
{
MessageBox.Show(ex.Message);
}
When i run this code from localhost all web api methods execute with out any issue .But in production only post methods are working and Get methods are returning 404 error .
Production is : .Net 4.5 and IIS 7