0
我試圖使用net start servicename
啓動我之前安裝的服務。C#服務:錯誤啓動服務:缺少標準構造函數
我可以確認服務安裝成功,管理工具區域中的註冊表和服務概覽中有條目。
實際上,我可以在事件日誌中看到一條錯誤消息,告訴我服務無法加載,因爲它沒有標準(無參數)構造函數。
的STRACK跡的最後兩行以下
bei Test.Service.DbService.OnStart(String[] args)
bei System.ServiceProcess.ServiceBase.ServiceQ...
我實現了服務於以下方式:
public partial class DbService : ServiceBase
{
public DbService()
{
InitializeComponent();
this.ServiceName = "Service1";
}
protected override void OnStart(string[] args)
{
if (serviceHost != null)
serviceHost.Close();
Uri[] baseAddress = new Uri[]{
//new Uri("http://localhost:8000"),
new Uri("net.pipe://localhost")};
string PipeName = "Test";
serviceHost = new ServiceHost(typeof(Kernel), baseAddress);
// Add a mex endpoint
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri("http://localhost:8000/DatabaseService/mex");
serviceHost.Description.Behaviors.Add(smb);
serviceHost.AddServiceEndpoint(typeof(IDatabase), new NetNamedPipeBinding(), PipeName);
serviceHost.Open();
}
protected override void OnStop()
{
// do stuff
}
}
,這就是我怎麼稱呼最初的服務:
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new DbService() //new instance of class implementing the service!
};
ServiceBase.Run(ServicesToRun);
}
你能證實我是這麼做嗎?
請參閱此處,它可能有所幫助:http://msmvps.com/blogs/theproblemsolver/archive/2011/04/19/inversion-of-control-and-wcf.aspx – Azodious
您是否記得安裝所有相關程序集(如果自第一次安裝以來有任何依賴關係發生了變化)? – jgauffin
存在一個依賴關係:我在自己的DLL中提取了服務契約,但是使用安裝程序(它列爲依賴項並將其複製到安裝文件夾中)發佈了該服務契約。 – inva