0
It is possible to make non-synchrone calls to
WebApi
?I don’t want my application to pass beaten by the method that executes the query to
WebApi
, I want her to expect a response and take an attitude as she returns, but all the examples I’ve seen of calls toWebApi
saneAsync
. What I must do?My architecture is what’s wrong?
in this example I would like to load the grid
private void btnListaGenerica_Click(object sender, EventArgs e)
{
Task<List<Empresa>> ListEmpresa = this.GetAll<Empresa>();
dgvDados.DataSource = ListEmpresa;
}
private async Task<List<T>> GetAll<T>()
{
try
{
using (var client = new HttpClient())
{
using (var response = await client.GetAsync("http://localhost:49783/api/empresas/listall"))
if (response.IsSuccessStatusCode)
{
//clienteUri = response.Headers.Location;
var ProdutoJsonString = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T[]>(ProdutoJsonString).ToList();
}
else
{
return null;
}
}
}
Impossible to answer this question without knowing which language will consume the API.
– mau humor
You use the API the way it is most convenient. What kind of example have you seen? front-end WEB applications?
– mau humor
I’m using C# in . net Webapi and a Xamarin app with c# as well
– Vagner Santos
could add the code snippet where you call the api?
– Leandro Araujo
You want to know if there is a way to control the behavior of the client application that will consume your Webapi without you programming the client side. That’s it?
– Pagotti
Guys, thank you so much for the help, responding to what Leandro asked and what Pagotti asked , I edited the question by putting the sample code excerpt. I tried to call the method that queries so List<Company> Listcompany = this.Getall<Company>(). Result But then the webapi query hangs and I have no idea why.
– Vagner Santos