[SOLVED] WCF TCP self-host works from within console app but not Windows service


This Content is from Stack Overflow. Question asked by dgwete

Windows 11 VS2019 vb.net. The WCF service listens on the specified port when hosted in a console app but fails to listen when hosted from within a Windows service. Verified by executing “netstat -aon”. I assume the problem is with my deployment of the windows service since everything works great when hosted in the console app. A client can connect, etc. All of this is being performed on the same computer so no firewall issues. But I did turn off the firewall to test. I also tried the service installation on a different computer with the same results. Since this my first post, I’ll try to include some code to demonstrate my config.

  <service behaviorConfiguration="WcfHomeCamInterface.Service1Behavior"
    <endpoint address="" binding="netTcpBinding" contract="WcfHomeCamInterface.IHomeCamService">
        <dns value="localhost" />
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <add baseAddress="net.tcp://localhost:9000" />
    <binding name="tcp_Unsecured"
      <security mode="None"/>
      <readerQuotas maxArrayLength="2147483647" />
    <behavior name="WcfHomeCamInterface.Service1Behavior">
      <!-- To avoid disclosing metadata information, 
      set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="False"/>
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true.  Set to false before deployment 
      to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="False" />


I’ve tried several different config file configurations with the same result. I’ve also tried different accounts from within the ProjectInstaller as well. However, the rest of the Windows service runs correctly – connects to the Sqllite database and executes all of the other subroutines. Do certain other windows services need to be running?? Any ideas would be appreciated, Thanks.


Check whether the port is occupied, and then run the following command:

netsh http add urlacl url=http://+:8080/ user="NETWORK SERVICE"

If something goes wrong, you can also delete it with this command:

netsh http delete urlacl url=http://+:8080/

As far as I know, debugging is a cumbersome and lengthy process, and I hope this method can help you.

This Question was asked in StackOverflow by dgwete and Answered by Jiayao It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?