Reputation: 19573
I have a WCF server that I can run as a service or as a windows forms application. When I run it as a Windows Forms application I can connect to it via my client application. However when I run it as a service using the same code, I cannot connect to it. I have confirmed that the service is running and doing its work. Below is the server's config 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 OnStart is called:
if (this.serviceHost != null)
{
this.serviceHost.Close();
}
this.serviceHost = new ServiceHost(typeof(ManagementService));
this.serviceHost.Open();
and the client's config 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>
Upvotes: 5
Views: 819
Reputation: 72930
Have you checked that you have that configuration defined in the config files for both the WinForms app and for the service?
Upvotes: 0
Reputation: 4051
Nothing in the event log about failing to register the address?
did you try to debug the service (using visual studio attach to process)?
Upvotes: 0
Reputation: 46052
If you are on the same machine, I would suggest using the NetNamedPipeBinding instead of WSHttpBinding. It's faster. You can always change back to the ws-http if you need cross-machine usage down the road.
Make sure your service is actually running via TaskManager. If not, put a Debugger.Break() statement in your service's constructor and step through to find where it fails to start. Here is a concise step-by-step for creating a Windows NT service in C# (if you need it).
Upvotes: 0
Reputation: 88475
Could you post the rest of your code for hosting the service?
Your class that starts the service should be inheriting from "ServiceBase" and should implement the "OnStart" and "OnStop" methods. These methods are invoked by the service console to start and stop the service process, so your ServiceHost should be opened/closed in these methods. Just wondering if maybe you're not doing that.
Upvotes: 2
Reputation: 1064224
What account is the service running as? I wonder if the service is failing to start, probably due to not having permissions to open the port.
Try running the service in your own identity (but as a service). If it works, it is a permissions issue. The most likely is the HTTP.SYS permissions.
To assign access, you use netsh on vista/window 7, or httpcfg on xp.
Upvotes: 1
Reputation: 36689
Where did you take the code that creates the service host from? My fist guess would be that when you run it as a service you either don't create the ServiceHost, or you don't keep the reference to it (so it gets garbage-collected)
Upvotes: 0