Hello there,
I have two Services called TemplateService, TemplateReportService (both defined in one WCF Service Library) to be exposed to the client application.
How can I host these two services under one Windows Service?
Please guide.
Thank you!
Hello there,
I have two Services called TemplateService, TemplateReportService (both defined in one WCF Service Library) to be exposed to the client application.
How can I host these two services under one Windows Service?
Please guide.
Thank you!
Yes, sure, no problem - you just need to open two service hosts:
protected override void OnStart(string[] args)
{
ServiceHost host1 = new ServiceHost(typeof(Service1));
ServiceHost host2 = new ServiceHost(typeof(Service2));
host1.Open();
host2.Open();
}
and of course you need to have the appropriate config entries for those two separate services in the Windows service's app.config file.
Marc
In the app.config for your Windows service, define a unique endpoint for each WCF service. Then in the OnStart() method of your Windows service, create a ServiceHost instance for each WCF service class.
Thank you Marc and Matt for your reply.
Here is snippet from my Windows Service App.config:
<services>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateService">
<endpoint address="ws" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateReportService">
<endpoint address="ws" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService" />
</baseAddresses>
</host>
</service>
</services>
And I have opened two hosts for these two services as specified by Marc.
But when I try to start my service, it says... 'service started and stopped...'. I looked into eventvwr for error detail and it says:
Service cannot be started. System.InvalidOperationException: Service 'ReportingComponentLibrary.TemplateReportService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
Any thoughts how I can avoid this error?
Thank you!