I have an assembly DLL that lets me connect to an ActiveMQ broker. Using the DLL from NUnit works fine and using it from a Console app works fine too. The problem is using it from a Windows Service. The connection to the broker always fails, as if there’s no external connectivity available to the service. Even bypassing the SCM and running the code in Visual Studio fails. Is there anything special a Windows Service project needs to do to get external connections?
The failing code in the DLL is this:
ConnectionFactory connectionFactory = new ConnectionFactory(connectURI);
connection = connectionFactory.CreateConnection(); // fails here
the connectURI is fine as it works in the Console app and the tests.
The main differnce is a console app and NUnit is running as the logged on user. A windows service runs as whatever you configure it to run as.
Try configuring the service to run as your account and see if it works. Make sure it’s not running as network service or local service.
The account it’s running as may need a user profile (has logged on before) especially if using a proxy server.
Try running fiddler or netmon to see what’s going on in the attempted connection. Also, try adding some logging and tracing around the connection attempt – the exception stack should have more details.
EDIT from comments: Also try adding .net web client connect code which will give a better insight into whatever connectivity issue there is. Obviously NMS is masking and swallowing the root issue.
EDIT: for others looking for the solution (without reading all the comments), adding the .web client code exposed the root issue which was a config file issue.