Windows service sharing information with a Rest

0

Is it possible for a Windows Service to exchange information with a Web Service Rest? If so, is this a good practice or not? Why the question? I just have to do the following. When a flag in the database is changed from 0 to 1, it should trigger a notification for an Android App. The way discussed here is to do a service, put a timer so that from time to time WS hears this change and triggers a notification.

    
asked by anonymous 05.10.2017 / 23:57

1 answer

0

Yes, it is possible.

First, install this NuGet in your Windows Service project.

After this, just make use of System.Net.Http.HttpClient . Here's an example of how to make the call in a very simple way. And also how to check the status of your call answer.

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://seu_endpoint_aqui/");

HttpResponseMessage response = client.GetAsync("api/allItems").Result;
if (response.IsSuccessStatusCode)
{
    var result = response.Content.ReadAsAsync<ImportResultDTO>().Result;
}
    
01.11.2017 / 01:32