I have a WCF server that I can run as a service or as an application for Windows forms. When I run it as a Windows Forms application, I can connect to it through my client application. However, when I start it as a service using the same code, I cannot connect to it. I confirmed that the service is up and running. The following is the server configuration file.
<system.serviceModel> <services> <service name="Cns.TrafficCopService.ManagementService"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/TrafficCop/ManagementService" /> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" contract="Cns.TrafficCopService.IManagementService" /> </service> </services> </system.serviceModel>
and its hosting code called 100 milliseconds after calling OnStart:
if (this.serviceHost != null) { this.serviceHost.Close(); } this.serviceHost = new ServiceHost(typeof(ManagementService)); this.serviceHost.Open();
and client configuration file:
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IManagementService" /> </wsHttpBinding> </bindings> <client> <endpoint address="http://localhost:8000/TrafficCop/ManagementService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IManagementService" contract="IManagementService" name="WSHttpBinding_IManagementService"> </endpoint> </client> </system.serviceModel>
source share