0
I was having trouble generating a graph, which is solved. The code below was ok and suddenly stopped, IE, the service is not running on account do not know what. At the time I call the Getservice nothing comes, the var itensgrid remains void.
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; }
}
}
That’s 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 that was working and I don’t know what I did. I already gave Ctrl+Z until I came back to nothing, I was doing Ctrl+Shift+Z and testing every step passed and I did not succeed.
Why am I no longer getting information that comes from my service with these codes? What’s wrong? When I hit one thing, I miss another. One in the harpsichord and one in the horseshoe.
EDIT1
You’re making this mistake
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 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 Authorizing Authorizing Authorizing Service Dataservice.Cs:60 }
For that 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);
}
}
If you call the api url directly with your ID the result appears?
– Leandro Angelo
@Leandroangelo, then, I put a break in the service call and it’s like this. He mounts the URL correctly, passing the correct parameter. But when you get here
var response = await client.GetStringAsync(url);
then it comes out of the method. I just want to understand why if it already worked and now it doesn’t. It doesn’t get in the catch, it just comes out of the method.– pnet
I believe this is giving "dick":
await client.GetStringAsync(url);
I tried to call directly and keeps leaving the method.– pnet
try using client.Getstringasync(url). Configureawait(false);
– Marco Souza
@Marconciliosouza, I had already done this and still still has problems. I do not understand, came to work, for three times I entered the break and now nothing.
– pnet
Your API is working ?
– Marco Souza
Yes, I press the Postman and the result comes. It’s OK.
– pnet