Service stopped working while generating the graph

0

I was having problems with generating a chart, which is solved. The code below was ok and suddenly stopped, ie the service is not running on account I do not know what. When I call GetService nothing comes up, the var itemsgrid remains null.

public class DataModelGrid
    {
        DataService dataService = new DataService();
        public List<LiberacaoItensGrid> itensGrid = new List<LiberacaoItensGrid>();
        public List<GeraGrafico> GeraChart { get; set; }
        public double IdOrcamento { get; set; }
        public double TotalVenda { get; set; }
        public double TotalLucro { get; set; }
        public DataModelGrid(double id)
        {
            GetService(id);
            GeraChart = new List<GeraGrafico>();
            GeraChart.Add(new GeraGrafico() { Assunto = "Vendas", Total = TotalVenda });
            GeraChart.Add(new GeraGrafico() { Assunto = "Lucro", Total = TotalLucro });
        }        
        public async void GetService(double id)
        {
            itensGrid = await dataService.GetDataGrid(id);
            foreach(var item in itensGrid)
            {
                this.IdOrcamento = item.IdOrcamento;
                this.TotalVenda = item.TotalVenda;
                this.TotalLucro = item.TotalLucro;
            }
        }
        public class GeraGrafico
        {
            public string Assunto { get; set; }
            public double Total { get; set; }
        }
    }

This is the code I use to get my service

public async Task<List<LiberacaoItensGrid>> GetDataGrid(double id)
        {
            try
            {
                string url = $"http://www.inetglobal.com.br/autorizador/api/getliberaitens/{id}";
                var response = await client.GetStringAsync(url);
                var itenslib = JsonConvert.DeserializeObject<List<LiberacaoItensGrid>>(response);
                return itenslib.ToList();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

The problem was working and I do not know what I did. I already gave Ctrl + Z until I went back to nothing, I was doing Ctrl + Shift + Z and testing each step and failed.

Why am I no longer able to get information coming from my service with these codes? What's wrong? When I hit one thing, I fail another. One on the stud and another on the horseshoe.

EDIT1

You're giving this error

  

Newtonsoft.Json.JsonReaderException: Unexpected character encountered   while parsing value: S. Path '', line 0, position 0. at   Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in   : 0 at   Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in   : 0 at   Newtonsoft.Json.JsonReader.ReadAndMoveToContent () [0x00000] in   : 0 at   Newtonsoft.Json.JsonReader.ReadForType   (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean   hasConverter) [0x00043] in: 0 at   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize   (Newtonsoft.Json.JsonReader reader, System.Type objectType,   System.Boolean checkAdditionalContent) [0x000db] in   : 0 at   Newtonsoft.Json.JsonSerializer.DeserializeInternal   (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053]   in: 0 at   Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader   reader, System.Type objectType) [0x00000] in   : 0 at   Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value,   System.Type type, Newtonsoft.Json.JsonSerializerSettings settings)   [0x0002d] in: 0 at   Newtonsoft.Json.JsonConvert.DeserializeObject [T] (System.String value,   Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in   : 0 at   Newtonsoft.Json.JsonConvert.DeserializeObject [T] (System.String value)   [0x00000] in: 0 at   Authorizer.Service.DataService + d__4.MoveNext ()   [0x0005b] in   C: \ Labs \ Authorizer \ Authorizer \ Authorizer \ Service \ DataService.cs: 60   }

For this code

public async Task<List<LiberacaoItensGrid>> GetDataGrid(double id)
        {
            try
            {
                //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 ....
                var itenslib = JsonConvert.DeserializeObject<List<LiberacaoItensGrid>>(response.ToString());

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

                }

                return itenslib.ToList();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    
asked by anonymous 24.10.2017 / 13:12

1 answer

2

change your Wait as follows.

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)
{

}

Solutionat Git

    
24.10.2017 / 14:16