title: Getting Connection Refused with WCF Service
body: <p>I made an service using WCF and can't connect to it, I keep getting the following error:</p>
  
  <blockquote>
    <p>Could not connect to net.tcp://localhost:5555/ControlChannel. The
    connection attempt lasted for a time span of 00:00:02.0139182. TCP
    error code 10061: No connection could be made because the target
    machine actively refused it 127.0.0.1:5555.</p>
  </blockquote>
  
  <p>This is the code:</p>
  
  <p>Contract:</p>
  
  <pre><code>[ServiceContract(CallbackContract = typeof(IControlChannelCallback))]
  public interface IControlChannel
  {
      [OperationContract]
      void Join();
  }
  </code></pre>
  
  <p>CallBackContract:</p>
  
  <pre><code>public interface IControlChannelCallback
  {
      [OperationContract(IsOneWay = true)]
      void ShowMessage(string message);
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
  public sealed class ControlChannel : IControlChannel
  {
      public static readonly IList&lt;IControlChannelCallback&gt; Callbacks = new List&lt;IControlChannelCallback&gt;(); 
  
      public void Join()
      {
          var client = OperationContext.Current.GetCallbackChannel&lt;IControlChannelCallback&gt;();
  
          if (!Callbacks.Contains(client))
              Callbacks.Add(client);
  
          client.ShowMessage("This message came from the server");
      }
  }
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>public MainForm()
  {
       InitializeComponent();
  
       using (var host = new ServiceHost(typeof(ControlChannel)))
       {
            host.Open();
       }
   }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>public MainForm()
  {
       InitializeComponent();
  
       var callback = new ControlChannelCallbackClient();
  
       using (var factory = new DuplexChannelFactory&lt;IControlChannel&gt;(callback, "Client"))
       {
            var proxy = factory.CreateChannel();
  
            proxy.Join();
       }
   }
  </code></pre>
  
  <p>App.config client:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
      &lt;system.serviceModel&gt;
        &lt;client&gt;
          &lt;endpoint name="Client"
                    contract="Service.Contracts.Interfaces.IControlChannel"
                    binding="netTcpBinding"
                    address="net.tcp://localhost:5555/ControlChannel" /&gt;
        &lt;/client&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>App.config server</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
      &lt;system.serviceModel&gt;
        &lt;services&gt;
          &lt;service name="Service.Contracts.Objects.ControlChannel"&gt;
            &lt;endpoint contract="Service.Contracts.Interfaces.IControlChannel"
                      binding="netTcpBinding"
                      address="net.tcp://localhost:5555/ControlChannel" &gt;
            &lt;/endpoint&gt;
          &lt;/service&gt;
        &lt;/services&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>What am I doing wrong? Is it a code problem or should I start looking for problems elsewhere?</p>