Windows service sharing information with a Rest

Asked

Viewed 44 times

0

Is it possible for a Windows Service to exchange information with a Web Service Rest? If so, is that good practice or not? Why the question? This is what I need to do. When a flag in the bank is changed from 0 to 1, it should trigger a notification for an Android App. The form discussed here earlier is to make a service, put a timer so that from time to time the WS listens to this change and trigger a notification.

  • It is possible yes, you can use Httpclient, here an example. And it’s a completely normal practice, in my opinion.

1 answer

0

It is possible yes.

First, install that Nuget in your Windows Service project.

After that, just make use of the System.Net.Http.Httpclient. Below is an example of how to call in a very simple way. And also how to check the status of your call response.

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;
}

Browser other questions tagged

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