title: Configuring WCF Endpoints? Chat server and client
body: <p>I'm trying to configure the WCF endpoints of my client program and my chat server program.</p>
  
  <p>When I get to the point where the logic is trying to connect (client login to server), I get the following error:</p>
  
  <blockquote>
    <p>Could not find endpoint element with name 'ChattingServiceEndpoint'
    and contract 'ChattingInterfaces.IChattingService' in the ServiceModel
    client configuration section. This might be because no configuration
    file was found for your application, or because no endpoint element
    matching this name could be found in the client element.</p>
  </blockquote>
  
  <p>This apparently happens while I am trying to open a DuplexChannelFactory in the code behind of the chat window in my WPF Chat Client: </p>
  
  <pre><code>_channelFactory = new DuplexChannelFactory&lt;IChattingService&gt;(new ClientCallback(), "ChattingServiceEndpoint");
  </code></pre>
  
  <p>I see the WCF configurations for the "ChattingServiceEndpoint" in BOTH the config files of both the client and the server. So what's really missing? Did I put the serviceModel tag in the wrong section of the app.config file? Do I need to include it in the app.config of the ChattingInterfaces library I am using to connect the client to the server?</p>
  
  <p>Here the app.config file for the client and server.</p>
  
  <p>app.config(server):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="ChattingServer.ChattingService"&gt;
          &lt;endpoint address="net.tcp://localhost:9000/ChattingService" binding="netTcpBinding" bindingConfiguration="" name="ChattingServiceEndPoint" contract="ChattingInterfaces.IChattingService" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-6.8.7.0" newVersion="6.8.7.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="MySql.Data.MySqlClient" /&gt;
        &lt;add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v11.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>app.config(client):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
  
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;&lt;/configSections&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v11.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-6.8.7.0" newVersion="6.8.7.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  &lt;connectionStrings&gt;&lt;add name="otongadgethubEntities" connectionString="metadata=res://*/OTonGadgetHub.csdl|res://*/OTonGadgetHub.ssdl|res://*/OTonGadgetHub.msl;provider=MySql.Data.MySqlClient;provider connection string=&amp;quot;server=localhost;user id=root;password=abc123;persistsecurityinfo=True;database=otongadgethub&amp;quot;" providerName="System.Data.EntityClient" /&gt;&lt;/connectionStrings&gt;
    &lt;system.serviceModel&gt;
      &lt;client&gt;
        &lt;endpoint address="net.tcp://localhost:9000/ChattingService" binding="netTcpBinding" bindingConfiguration="" contract="ChattingInterfaces.IChattingService" name="ChattingServiceEndPoint" kind="" endpointConfiguration="" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="MySql.Data.MySqlClient" /&gt;
        &lt;add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;&lt;/configuration&gt;
  </code></pre>
  
  <p>Here's the codebehind for the window where the error occurs:</p>
  
  <pre><code>using ChattingInterfaces;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.ServiceModel;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Shapes;
  
  namespace ChatClient
  {
      /// &lt;summary&gt;
      /// Interaction logic for ChatWPFClient.xaml
      /// &lt;/summary&gt;
      public partial class ChatWPFClient : Window
      {
          //our current logged in user that will be set at MainWindow at login
          public static user loggedInUser;
  
          public static IChattingService Server;
          private static DuplexChannelFactory&lt;IChattingService&gt; _channelFactory;
          public ChatWPFClient()
          {
              InitializeComponent();
              _channelFactory = new DuplexChannelFactory&lt;IChattingService&gt;(new ClientCallback(), "ChattingServiceEndpoint");
              Server = _channelFactory.CreateChannel();
  
              int returnValue = Server.Login(loggedInUser.username);
              if (returnValue == 1)
              {
                  MessageBox.Show("You are already logged in, check to see who is logged into system");
  
              }
              else if (returnValue == 0)
              {
                  MessageBox.Show("You are now logged in! Welcome!");
                  welcomeLabel.Text = "Welcome, " + loggedInUser.username;
  
              }
          }
  
          private void sendMessage(object sender, RoutedEventArgs e)
          {
              //MessageBox.Show("Not available yet!");
  
              //TODO: Change username
              if (chatEntryField.Text.Length == 0)
              {
                  return;
              }
              Server.SendMessageToALL(chatEntryField.Text, "Test");
              TakeMessage(chatEntryField.Text, "Test");
              chatEntryField.Text = "";
          }
  
          public void TakeMessage(string message, string userName)
          {
              chatBox.Text += userName + ": " + message + "\n";
              //TODO: Scroll chatBox to end
          }
      }
  }
  </code></pre>
  
  <p>IChattingService.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  
  namespace ChattingInterfaces
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IChattingServices" in both code and config file together.
      [ServiceContract(CallbackContract=typeof(IClient))]
      public interface IChattingService
      {
          [OperationContract]
          int Login(string userName);
          [OperationContract]
          void SendMessageToALL(string message, string userName);
      }
  }
  </code></pre>
  
  <p>ChattingService.cs:</p>
  
  <pre><code>using ChattingInterfaces;
  using System;
  using System.Collections.Concurrent;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  
  namespace ChattingServer
  {
      [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
      public class ChattingService : IChattingService
      {
          //private ConnectedClient _connectedClients;
  
          public ConcurrentDictionary&lt;string, ConnectedClient&gt; _connectedClients = new ConcurrentDictionary&lt;string, ConnectedClient&gt;();
  
          public int Login(string userName)
          {
              //is anyone else logged in with my name?
              foreach (var client in _connectedClients)
              {
                  if(client.Key.ToLower() == userName.ToLower())
                  {
                      //if yes
                      return 1;
                  }
              }
  
              var establishedUserConnection = OperationContext.Current.GetCallbackChannel&lt;IClient&gt;();
  
              ConnectedClient newClient = new ConnectedClient();
              newClient.connection = establishedUserConnection;
              newClient.UserName = userName;
  
  
  
              _connectedClients.TryAdd(userName, newClient);
  
              return 0;
          }
  
  
          public void SendMessageToALL(string message, string userName)
          {
              foreach (var client in _connectedClients)
              {
                  if (client.Key.ToLower() != userName.ToLower())
                  {
                      client.Value.connection.GetMessage(message, userName);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I am willing to post more code files as necessary to help diagnose this problem. Anyone got an idea of what to do/what's going on? Thanks!</p>