Hello Team,
I have a window service in which I am consuming a 3rd party rest service and based on response inserting that data in our SQL database.
Window service is running continuously on the system and based on a timer invoking a method.
Its working fine but failing in one scenario when my consumed 3rd party rest service goes down then its giving below error message -
The remote server returned an error: (400) Bad Request. After this error message window service scheduling its next run after 1 hrs and it again giving the same above error message while 3rd party service had been up and running fine. In every next run its giving similar error message.
To resolve the issue I stopped the window service and started again through service.msc console. After every restart of service its working fine but when its calling similar method via timer then its not working.
I am using below code -
// Call 3rd party service
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
httpWebRequest.Method = "GET";
httpWebRequest.Headers.Add("Authorization", authCode);
HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
}
I did some google and find that we also need to close the response and Abort the request but I am not sure If this could resolve the problem..
Thanks in advance for your response.