I have a small console app containing a web server written in c#. When trying to convert it to windows service, i get a error 1053, and when i view the error log it shows:
Application: YCSWebServerService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.DirectoryNotFoundException
Stack:
at HttpServer.Resources.FileResources.Add(System.String, System.String)
at HttpServer.Resources.FileResources..ctor(System.String, System.String)
at YCSWebServer.WebServer..ctor(SerialCommunication.SerialCommunicationWrapper, YCSInterfaces.IBuilder, SerialCommunication.SerialCommunication)
at YCSConfiguration.Builder..ctor()
at YCSWebServerService.YCSWebServerService..ctor()
at YCSWebServerService.Program.Main()
which is due to the following code:
server = new Server();
// Where to find the html page to render
server.Resources.Add(new FileResources("/", ".\\Webpages"));
server.Add(new FileModule(server.Resources, false));
//Create a http listener
HttpListener listener = HttpListener.Create(IPAddress.Any, 8888);
// use one http listener.
server.Add(listener);
server.RequestReceived += ServerRequestReceived;
// start server, can have max 10 pending accepts.
server.Start(10);
I have trying setting a relative path to where my html files are located, and i have trying giving it a fixed path fx: c:\webpages, but without success. I always get the same error. Do i have set some kind of permission/security in order for my service to access this folder?? The webserver is based on a codeplex project: http://webserver.codeplex.com/
My onstart and onstop methods:
public partial class YCSWebServerService : ServiceBase
{
private Builder _builder;
public YCSWebServerService()
{
InitializeComponent();
_builder = new Builder();
}
protected override void OnStart(string[] args)
{
_builder.Start();
}
protected override void OnStop()
{
_builder.Stop();
}
}