Quantcast
Viewing all articles
Browse latest Browse all 1535

Microsoft Windows service not continuing after API response

I have created a service using the ServiceBase class. Every minute the service will check to see if there are files in a directory, read those files, send an API call, and then move the read files into a new directory. Within a GUI application, I can run the code which is responsible for checking the directory, reading those files, sending the API call, and moving the files into a new directory. The process is completed as desired when using the GUI application, however, when the service is running the same process it is having unexpected behavior with the code below.

helpers.Write2Log("Creating request to server");HttpResponseMessage response;            try{    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri)    {        Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json")    };    response = await client.SendAsync(request);}catch (Exception ex){    helpers.Write2Log(ex.Message);    throw new Exception(ex.Message);}helpers.Write2Log("Got a response back from server");

I can see using Wireshark that the HTTP call is being sent and I am receiving a response back from the server, but nothing is written to the log after the 'Creating request to server' message. I can also see that the API is doing what it is supposed to. When I attach a debugger to the service, the debugger will stop on response = await client.SendAsync(request) and never continue on. My expectation is that the debugger would continue on after receiving the response back from the server. I do not understand why the thread will not continue after receiving a response. Any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 1535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>