I'm getting error when trying to call a method from a Web API.
Method declaration in ApiController
public class AcessoController : ApiController
{
[HttpGet]
public UsuarioModel ValidarUsuario(string login, string senha, string modoAutenticacao)
{
}
}
Consuming the API
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["UrlAPI"]);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = new HttpResponseMessage();
response = await client.GetAsync(string.Format("api/Acesso/ValidarUsuario?login={0}&senha={1}&modoAutenticacao={2}", model.Login, model.Senha, (model.ModoAutenticacao == LoginViewModel.Dominio.Computecnica) ? "interno" : "externo"));
if (response.IsSuccessStatusCode) //esta retornando falso
{
}
Error:
Can not be null Parameter name: root
It seems to be a failure to construct the URL, since the execution of this method worked through UnitTest .