1

I have a windows service (.NET), that is trying to connect to a remote client. But it is throwing an exception. While I tested the same code, as an windows application, there was no such issue.

The error:

Unable to connect to the remote serverSystem.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

My code:

var wb = new WebClient()
var response = wb.UploadValues(ConfigurationManager.AppSettings["Query"], "POST", data);

Most importantly, the same code works in development environment while running it as a part of Windows forms application.

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
santubangalore
  • 796
  • 1
  • 12
  • 25
  • Which user account is running your service? Most likely this user is not allowed to access network/internet resources. Check your System and Application Event Log for more details. – Filburt Jun 23 '15 at 12:37
  • @Filburt no, that is a TCP level error. Permissions have not come into play yet. – usr Jun 23 '15 at 12:45
  • @usr I might be missing something, but if the service is running under LOCALMACHINE (instead of NETWORKSERVICE) it's likely that he won't be able to create said tcp connection. – Filburt Jun 23 '15 at 12:50
  • @Filburt as far as I understand both accounts have TCP access to anything but they can't "present" certain Windows credentials. http://stackoverflow.com/questions/510170/the-difference-between-the-local-system-account-and-the-network-service-acco My understanding of that is very limited, though. – usr Jun 23 '15 at 12:58

1 Answers1

1

It got solved it changing the profile in control panel-> admin tools -> service -> select service name ->stop-> right click properties -> log on -> change from Local system to this account -> provided my credentials -> click on apply -> OK.

Restart the service. BTW I had admin privileges.

santubangalore
  • 796
  • 1
  • 12
  • 25