我有一個小型控制檯應用程序,其中包含用c#編寫的Web服務器。當試圖將其轉換爲Windows服務,我得到一個錯誤1053,當我查看錯誤日誌它顯示:Windows服務提供錯誤1053 - System.IO.DirectoryNotFoundException
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()
這是由於下面的代碼:
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);
我已經嘗試設置我的html文件所在位置的相對路徑,我試圖給它一個固定路徑fx:c:\ webpages,但沒有成功。我總是得到同樣的錯誤。 爲了讓我的服務能夠訪問此文件夾,我是否設置了某種權限/安全性? 的Web服務器是基於一個CodePlex項目:http://webserver.codeplex.com/
我的OnStart和的onStop方法:
這奏效了!謝謝! – lmkk 2010-06-28 13:20:18