-3

When I do the request using Postman I get:

enter image description here

This is what I am expecting:

public class Result<TResultType>
{
    public int? ErrorId { get; protected set; } // Todo: Use it!!!
    public bool Success { get; protected set; }
    public ResponseErrorType ErrorType { get; protected set; }
    public string Message { get; protected set; }
    public TResultType Data { get; protected set; }
}

In this case, TResultType is:

public class SettingsResponse : BaseResponse
{
    public string LocationCode { get; set; }
    public string Ip { get; set; }
    public int Port { get; set; }
    public string ApplicationPrinterName { get; set; }
    public string MerchantNumber { get; set; }
    public string MessageControl { get; set; }
    public string PRIN { get; set; }
    public string SoftwareName { get; set; }
    public string SoftwareVersion { get; set; }
    public string SystemNumber { get; set; }
}

This is how I'm doing the request:

using (HttpClient client = GetHttpClient())
{
    var responseTask = client.GetAsync($"{url}/{paramsStr}");
    if (await Task.WhenAny(responseTask, Task.Delay(TimeoutSeconds * 1000)) == responseTask)
    {
        var response = await responseTask;
        return response.IsSuccessStatusCode
            ? await response.Content.ReadAsAsync<Result<TResponse>>()
            : default(Result<TResponse>);
    }

    return Result<TResponse>.FromTimeout();
}

I'm always getting null in the property Data, even when the values are there in the json response.

  • 2
    Without code, I can simply offer "there is no spoon." – Greg May 07 '18 at 15:15
  • So what? All you are showing is a partial JSON with values masked. What is your question? What does your call look like, what do expect it to return etc? – Cetin Basoz May 07 '18 at 15:15
  • 3
    a) Don't post images of code. b) Without an [mcve] this question is going to be closed and go unanswered. – ProgrammingLlama May 07 '18 at 15:20
  • 2
    We don't want your object, but how you are performing your request to receive your HttpResponse – Greg May 07 '18 at 15:20
  • 3
    [Images of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question). Please copy and paste your code into your question. And show us how you're performing your request!!!!! – ProgrammingLlama May 07 '18 at 15:22
  • this is the code that is giving the return value: await response.Content.ReadAsAsync>() – Lizzael Villar Cruz May 07 '18 at 15:39

1 Answers1

1

Result class with public setters in properties

public class Result<TResultType>
{
    public int? ErrorId { get; set; } // Todo: Use it!!!
    public bool Success { get; set; }
    public ResponseErrorType ErrorType { get; set; }
    public string Message { get; set; }
    public TResultType Data { get; set; }
}

It is working now.