Extension method (Wait () and Status ()) does not work

-1

This is not working (only the Wait () and Status () lines)

try
            {
                string url = $"http://localhost:2710/api/faturamento/{IdUsuario}/{IdGaragem}";
                var uri = string.Format(url);
                var response = await client.GetStringAsync(uri);

                response.Wait(); // AQUI DÁ O ERRO

                while (response.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)// AQUI DÁ O ERRO
                {

                }

                var desvio = JsonConvert.DeserializeObject<List<DesvioFaturamento>>(response);
                return desvio;
            }
            catch(Exception ex)
            {
                string erro = ex.Message;

                return null;
            }

give this error:

  

"string" does not contain a setting for "Wait" and was not possible   find any "Wait" extension method that accepts a first   argument of type "string" (there is a use directive or reference of   assembly missing?)

     

"string" does not contain a setting for "Status" and could not be   find any "Status" extension method that accepts a first   argument of type "string" (there is a use directive or reference of   assembly missing?)

P.S. I have another Xamarin.Forms project that these lines are working and I have the same references.

EDIT1

This one is working here

public async Task<List<LiberacaoItensGrid>> GetDataGrid(double id)
        {
            try
            {
                //var client = new HttpClient();
                //string url = $"http://www.inetglobal.com.br/autorizador/api/getliberaitens/{id}";

         //var response = await client.GetStringAsync(url);
                //var itenslib = JsonConvert.DeserializeObject<List<LiberacaoItensGrid>>(response);

                var client = new HttpClient();
                string url = $"http://www.inetglobal.com.br/autorizador/api/getliberaitens/{id}";
                var response = client.GetStringAsync(url);

                response.Wait(); // use assim ou com o while ....

                while (response.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
                {

                }
                var itenslib = JsonConvert.DeserializeObject<List<LiberacaoItensGrid>>(response.Result.ToString());

                return itenslib.ToList();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    
asked by anonymous 09.01.2018 / 17:07

1 answer

1

The method Wait is a method of Task and respose is a string .

Note that in the first code you have keyword await , this causes the task to be resolved and that the response variable is of type string .

Your code looks like this

var response = await client.GetStringAsync(uri);

Should be

var response = client.GetStringAsync(uri);
    
09.01.2018 / 17:29