'C# Service HttpClient reponse null

I have gone through all the possible posts and I have not found any solution that works for me (There is no more to see the mess in imports), please help. :(

I am building a windows service in c# and I need to call a web service every X time and check if it has to do something. (Collect instructions)

I attach the entire code:

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Reflection;
using System.ServiceProcess;
using System.Timers;
using System.Text;

namespace TestServiceCreateFile
{

public partial class Service1 : ServiceBase
{
    /* Config values */
    int CheckRobotStatusTimerMills = 10000;
    static string MachineKey = "";

    private static readonly HttpClient client = new HttpClient();
    EventLog EventLog = new System.Diagnostics.EventLog();

    public Service1()
    {
        this.ServiceName = "BotBrainExecutor";
        this.EventLog.Source = this.ServiceName;
        this.EventLog.Log = "Application";

        ((ISupportInitialize)(this.EventLog)).BeginInit();
        if (!EventLog.SourceExists(this.EventLog.Source))
        {
            EventLog.CreateEventSource(this.EventLog.Source, this.EventLog.Log);
        }
        ((ISupportInitialize)(this.EventLog)).EndInit();

    }

    protected override void OnStart(string[] args)
    {
        LoadConfig();

        Timer timer = new Timer();
        timer.Interval = CheckRobotStatusTimerMills;
        timer.Elapsed += (s, e) => MainFunctionAsync(s, e);
        timer.Start();


        base.OnStart(args);
    }

    private string URLGetOrdersOrch = "http://localhost:8080/testing?machinekey=" + MachineKey;
    public async Task MainFunctionAsync(object sender, ElapsedEventArgs args)
    {
        LogLine("Start" + " " + DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss"));

        HttpClient httpClient = new HttpClient();
        HttpResponseMessage response = await httpClient.GetAsync(URLGetOrdersOrch);

        if (response.IsSuccessStatusCode)
        {
            LogLine("Response OK");

            LogLine(await response.Content.ReadAsStringAsync());
        }
        else
        {
            LogLine((int)response.StatusCode + " " + response.ReasonPhrase);
        }

    }

The problem is that the result of the Http is correct and it registers in the log 'Response OK', so it is entering the 'if', but it never gets to collect the result:

log image

Thank you!



Solution 1:[1]

This was totally my fault. the code was fine, but it had a method to register the logs that had a string format. So when I received a '{', the method interpreted it as a parameter being passed to it. I will keep the post for others to see.

Thanks to all for the help.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moustached Monkey