Restsharp connected with Firebase but shows no result

Asked

Viewed 132 times

0

I did a job in C# and now I need to connect this service with my bank on Firebase. The following is the method in Library for connection with the Firebase:

public static void restAPI()
    {
        var client = new RestClient("https://teste.firebaseio.com/");
        var request = new RestRequest("users.json", Method.GET);
        var queryResult = client.Execute<List<Items>>(request).Data;

        Library.WriteErrorLog("RESTAPI: " + queryResult);
    }

Function in the Shceduler to initialize the service and call the method:

protected override void OnStart(string[] args)
    {
        Library.restAPI();
        if (Library.IsConnected())
        {
            Library.WriteErrorLog("////// Com conexão! //////");
            timer1 = new Timer();
            this.timer1.Interval = 3000;
            this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
            Library.WriteErrorLog(">> Test Window Service iniciado! <<");
            if (!File.Exists(docBase))
            {
                File.Copy(pricetabLocal, docBase);
                listaBase = Library.MontarListaBase(docBase, ref copiado);
                Library.WriteErrorLog("<< FIM! >>" + copiado);
            }
            else
            {
                Library.WriteErrorLog("Ja existe um arquivo com este nome!");
                listaBase = Library.MontarListaBase(docBase, ref copiado);
                Library.WriteErrorLog("<< FIM! >>" + copiado);
            }
            timer1.Enabled = true;
        }
        else
        {
            Library.WriteErrorLog("////// Sem conexão! //////");
        }
    }

Public Class Items:

public class Items
    {
        public string usuarios { get; set; }
    }

THINK I was able to make the connection but I can’t see the correct content, the answer that returns is as follows:

RESTAPI: System.Collections.Generic.List`1[Testwindowsservice.Library+Items]

ps: that answer I write in a notebook.

What does that answer mean? Connected how do I "pan" this answer to format it?

2 answers

1

< REPLY >

To get what’s in the database Firebase in format JSON I just modified my method:

public static void restAPI()
    {
        var client = new RestClient("https://teste.firebaseio.com/.json");
        var request = new RestRequest("", Method.GET);
        request.RequestFormat = DataFormat.Json;
        IRestResponse requestget = client.Execute(request);
        Library.WriteErrorLog("RESTAPI: " + requestget.Content);
    }

1

This is the default output for type List<T>.

If you want to specify what should be written in the file, do this

public static void restAPI()
{
    var client = new RestClient("https://segundo-chat.firebaseio.com/");
    var request = new RestRequest("users.json", Method.GET);
    var queryResult = client.Execute<List<Items>>(request).Data;

    foreach(Items item in queryResult)
    {
        Library.WriteErrorLog("Resultado: " + item.usuarios);
    }
}
  • Speaks @jbueno, improved my post this time? rs. I edited and put my class to which you refer in your reply (which lacks a Items structure). I made the adjustments you said but now the answer is blank.

  • So, young man. you’ve improved a lot, I can understand your question at first. The point is that you involved some unnecessary things, your only problem (at least in the scope of the publication) was that you didn’t know what you were writing in the file. By the way, seeing this "problem" of yours, I feel obliged to say that you are lacking basis for you, it seems to me that you have parachuted and are trying to do something with C#. It would be good to study language first, have some knowledge base. I have the impression that you are completely lost in it.

  • 1

    About the solution: try to do this -> Library.WriteErrorLog("RESTAPI: " + queryResult.Count); and tell me what the written result was. By the way, you know how to debug the code?

  • The answer was: RESTAPI: 1

  • Well, that means your query has returned one item. Now, without further details, I have no way to help you.

  • Okay, thank you!!!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.