title: WCF port not listening
body: <h2>Update</h2>
  
  <p>The service is running and has a pid in Task Manager but when I run <code>netstat -ano | find pid#</code> nothing is returned - the port is not listening.</p>
  
  <p>Also if I run <code>netstat -ap tcp</code> the port is not listed.</p>
  
  <p>I really don't know how to fix this. In summary so you don't have to read my previous post:</p>
  
  <ul>
  <li>My WCF Service works perfectly under localhost (ie service and client on same server)</li>
  <li>When I publish the Service to a production server, the service installs fine but the 8523 port does not listen</li>
  <li>There are several similar posts that I have reviewed but none work for me</li>
  <li>This is my first WCF project that I have attempted so I have exhausted my knowledge and I can't find any more examples on the Internet to try</li>
  <li>At this point I will be very grateful for any pointers</li>
  </ul>
  
  <h2>environment</h2>
  
  <ul>
  <li>development: Windows 7</li>
  <li>Visual Studio: 2015</li>
  <li>production server: Windows Server 2008 R2 Datacenter</li>
  <li>IIS version 7.5.7600.16385</li>
  </ul>
  
  <h2>Introduction</h2>
  
  <p>I have researched this issue for a few days now and although I have found a number of similar questions on Stack Overflow, none of those questions solve my problem; therefore I don't think this is a duplicate and it will be specifically helpful if someone is trying to follow the referenced Microsoft tutorial as I have done</p>
  
  <h2>Problem details</h2>
  
  <p>I have followed this Microsoft article "How to: Host WCF in a Windows Service Using TCP" at <a href="https://msdn.microsoft.com/en-us/library/ff649818.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/ff649818.aspx</a>.</p>
  
  <p>After creating the solution, it runs perfectly on my development machine within the Visual Studio localhost environment. The tutorial suggests that you create a Test Client to access the WCF solution and that Test client works successfully</p>
  
  <p>When I publish the WCF Service and the Windows Service in the production machine (Windows Server 2008) it again installs without error. Here are the steps that I follow:</p>
  
  <p><em>IIS Setup</em></p>
  
  <ul>
  <li><p>add net.tcp to the enabled protocols</p></li>
  <li><p>activate 'Windows Communication Foundation Non-HTTP Activation'</p></li>
  <li><p>Changed bindings for net.tcp to 8532</p></li>
  <li><p>Ensure 'Net.Tcp Listener Adapter' is running</p></li>
  </ul>
  
  <p><em>Open 8532 port in firewall</em></p>
  
  <p><em>Browse to the bin directory of the project where WindowsService1.exe is located and run the exe as administrator</em></p>
  
  <p><em>Open command Prompt as administrator and run Installutil WindowsService1.exe</em></p>
  
  <h2>Differences between Localhost (development environment in Visual Studio) and Production environment</h2>
  
  <p>The only changes between the localhost WCF system and production system is I changed the baseAddress in app.conf from </p>
  
  <ul>
  <li>"net.tcp://localhost:8523/CustomWCFService" </li>
  </ul>
  
  <p>to</p>
  
  <ul>
  <li>"net.tcp://10.2.1.1:8523/CustomWCFService"</li>
  </ul>
  
  <p>Here is the deployed app.conf</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="MyCustomServiceLib.CustomServiceLib"&gt;
          &lt;endpoint address="" binding="netTcpBinding" bindingConfiguration=""
            contract="MyCustomServiceLib.ICustomServiceLib"&gt;
            &lt;identity&gt;
              &lt;dns value="localhost" /&gt;
            &lt;/identity&gt;
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
            contract="IMetadataExchange" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="net.tcp://10.2.1.1:8523/CustomWCF" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name=""&gt;
            &lt;serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <h2>Adding Service Reference</h2>
  
  <p>When I try to add the service reference in my application that will use the WCF service. I get this error:</p>
  
  <blockquote>
    <p>There was an error downloading metadata from the address. Please
    verify that you have entered a valid address</p>
  </blockquote>
  
  <p>When I click on "Details" I see this:</p>
  
  <blockquote>
    <p>The URI prefix is not recognized. Metadata contains a reference that
    cannot be resolved: 'net.tcp://10.2.1.1:8523/CustomWCF'. Could not
    connect to net.tcp://10.2.1.1:8523/CustomWCF. The connection attempt
    lasted for a time span of 00:00:01.0312368. TCP error code 10061: No
    connection could be made because the target machine actively refused
    it 10.2.1.1:8523.  No connection could be made because the target
    machine actively refused it 10.2.1.1:8523 If the service is defined in
    the current solution, try building the solution and adding the service
    reference again.</p>
  </blockquote>
  
  <h2>What I have tried</h2>
  
  <p>A lot of the other WCF questions asked on forums seem to be in regards to getting the service working in localhost which does not apply to me because the solution I've created works perfectly in the development environment.</p>
  
  <p>Some of the answers suggest enabling tcp port sharing in the project but when I try and add this code in my solution I get an error saying "not allowed".</p>
  
  <p>Other questions suggest that the url must be registered on the production server but that has no effect.</p>
  
  <p>After trying all the forum suggestions that I can find and trying to correct everything that I think is wrong, I've still have no luck.</p>
  
  <p>Any suggestions or pointers will be greatly appreciated </p>