title: How do I solve SecurityNegotiationException and InvalidCredentialException in WCF
body: <p>So I've written a small game and wish for the game to be playable over the internet.</p>
  
  <p>I've been testing the game just through localhost using these configs:</p>
  
  <p>Client Winapp Application:</p>
  
  <p>App.Config file</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 ="CommandBoard"
                    address="net.tcp://localhost:9000/commandboard"
                    binding = "netTcpBinding"
                    contract="CommandBoardServiceLibrary.ICommandBoardService"/&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>While in the Client Winform Code I have it connecting like this</p>
  
  <pre><code>ChannelFactory&lt;ICommandBoardService&gt; remoteFactory= new ChannelFactory&lt;ICommandBoardService&gt;("CommandBoard");
  ICommandBoardService proxy = remoteFactory.CreateChannel();
  </code></pre>
  
  <p>Next, to host the service I create a console app.</p>
  
  <p>the App.config is basic. I changed nothing, only in the actual code.</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;/configuration&gt;
  </code></pre>
  
  <p>Console app code:</p>
  
  <pre><code>static void Main(string[] args)
  {
      using (ServiceHost host = new ServiceHost(typeof(CommandBoardServiceLibrary.CommandBoardService)))
      {
          host.AddServiceEndpoint(typeof(
              CommandBoardServiceLibrary.ICommandBoardService),
              new NetTcpBinding(),
              "net.tcp://localhost:9000/commandboard");
          host.Open();
  
          Console.ReadLine();
       }
  }
  </code></pre>
  
  <p>Running both the client and the host at the same time works perfectly on my computer. </p>
  
  <p>Now when I change the client's App.Config to</p>
  
  <pre><code>&lt;client&gt;
      &lt;endpoint name ="CommandBoard"
                address="net.tcp://23.122.59.211:9000/commandboard"
                binding = "netTcpBinding"
                contract="CommandBoardServiceLibrary.ICommandBoardService"/&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p>and run it on a different computer on a different Network I get the following error:
  <code>System.ServiceModel.Security.SecurityNegotiationException: The server has rejected the client credentials. ---&gt; System.Security.Authentication.InvalidCredentialException: The server has rejected the client credentials. ---&gt; System.ComponentModel.Win32Exception: The logon attempt failed</code></p>
  
  <p>Where is the source of this error? Have a configured it incorrectly? Or am I missing something?</p>
  
  <p>EDIT: Web.config for the WCF service</p>
  
  <pre><code>&lt;?xml version="1.0"?&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" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5"/&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
            &lt;!-- 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 --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;protocolMapping&gt;
          &lt;add binding="basicHttpsBinding" scheme="https" /&gt;
      &lt;/protocolMapping&gt;    
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
      &lt;!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        --&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>