I’m trying to start my previously installed service using net start servicename.
I can confirm that the service was installed successfully, there are entries in the registry and in the service overview within the administration tools area.
Actually I can see an error message within the event log telling me that the service could not be loaded because it does not have an standard (parameter-less) constructor.
The last two lines of the strack trace are the following
bei Test.Service.DbService.OnStart(String[] args)
bei System.ServiceProcess.ServiceBase.ServiceQ...
I implemented the service in the following way:
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
}
}
and that’s how I call the service initially:
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new DbService() //new instance of class implementing the service!
};
ServiceBase.Run(ServicesToRun);
}
Can you confirm that I’m doing this right?
I got it, it was so simple that I just was aware of that. The key is: i re-read the error message a couple of times until i recognized that it was telling me that the “service-type” does not contain a standard constructor what actually is completely correct. this is the line of interest: serviceHost = new ServiceHost(typeof(Kernel), baseAddress); the class “Kernel” does not contain an standard constructor, thats it. I added a constructor without any parameters to it and its working. Thanks for your ideas and your support!