I am having problems hosting a WCF service in a Windows service. I can start my WCF service in VS2008 and navigate to the base address in my app.config
<configuration> <system.web> <compilation debug="true" /> </system.web> <system.serviceModel> <services> <service behaviorConfiguration="WCF.IndexerBehavior" name="WCF.Indexer"> <endpoint address="" binding="wsHttpBinding" contract="WCF.IIndexer"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost/WCFService/Action/" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WCF.IndexerBehavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
I see that it works fine, I get a page that says that I created a sample service and code, how to use it.
Now my next step was to create a Windows service to host my WCF as shown above.
I just used the te windows service template, it gave me Program.cs and Service1.cs, which I renamed to WindowsServiceHost.cs. In it I:
private ServiceHost host; public WindowsServiceHost() { InitializeComponent(); } protected override void OnStart(string[] args) { try { var serviceType = typeof(Indexer.WCF.Indexer); host = new ServiceHost(serviceType); host.Open(); } catch (Exception ex) { } } protected override void OnStop() { if (host != null) { host.Close(); } }
Everything compiles fine, I can run InstallUtil (I defined the installer). The service, which was used to immediately start and stop, but disabling Windows Defender, got rid of this. Now the service starts (as a network service) and remains (I think), but when I go to the base address, I get a page not found. Another weird thing is when I try to stop the service (which still shows up as work), I get:
Error 1061: the service cannot receive control messages at this time
I tried everything but do not understand.
source share