title: CreateChannel with ClientCredentials property
body: <p>I'm pretty new to WCF and trying to create a WCF service with custom username and password. I know that I should set the userName and Password to the proxy's ClientCredentials, but out of some reason, I have no such a property...</p>
  
  <p>I assume it has something to do with my Contract, so here it is:</p>
  
  <p>My contract code:</p>
  
  <pre><code>namespace Contracts
  {    
      [ServiceContract]
      public interface ICalc
      {
          [OperationContract]
          CalcResponse Add(double x, double y);
  
          [OperationContract]
          CalcResponse Substract(double x, double y);
  
          [OperationContract]
          CalcResponse Multiply(double x, double y);
  
          [OperationContract]
          CalcResponse Divide(double x, double y);
      }
  }
  </code></pre>
  
  <p>In my client all I try to do is:</p>
  
  <pre><code>ChannelFactory&lt;ICalc&gt; channel = new ChannelFactory&lt;ICalc&gt;("calcEndpoint");
  ICalc proxy = channel.CreateChannel();
  
  proxy.ClientCredentials.UserName.UserName = "USER";
  proxy.ClientCredentials.UserName.Password = "PASSWORD";
  </code></pre>
  
  <p>But my proxy doen't have a ClientCredentials property</p>
  
  <p><strong>Update:</strong>
  I had some issues that causes some other errors. As I solved them, I got a new error:</p>
  
  <blockquote>
    <p>The socket connection was aborted. This could be caused by an error
    processing your message or a receive timeout being exceeded by the
    remote host, or an underlying network resource issue.</p>
  </blockquote>
  
  <p>My timeout is 5 set to 5 minutes in both client and server. I get this error after less than a minute...</p>
  
  <p>Here's my updated code:</p>
  
  <pre><code>ChannelFactory&lt;ICalc&gt; channel = new ChannelFactory&lt;ICalc&gt;("calcEndpoint");
  
  var defaultCredentials = channel.Endpoint.Behaviors.Find&lt;ClientCredentials&gt;();
  channel.Endpoint.Behaviors.Remove(defaultCredentials);
  
  ClientCredentials loginCredentials = new ClientCredentials();
  loginCredentials.UserName.UserName = "Comply";
  loginCredentials.UserName.Password = "123456";
  
  channel.Endpoint.Behaviors.Add(loginCredentials); 
  ICalc proxy = channel.CreateChannel();
  </code></pre>
  
  <p>I have a custom validator, I put a breakpoint there, but it just didn't make it there...
  My validator code:</p>
  
  <pre><code>class CustomUserNameValidator : UserNamePasswordValidator
  {
      public override void Validate(string userName, string password)
      {
          if (userName == "comply" &amp;&amp; password == "123456")
          {
          }
      }
  }
  </code></pre>
  
  <p>The config (on both client and server):</p>
  
  <pre><code>&lt;service name ="WcfServiceLibrary.Service1" behaviorConfiguration ="CustomValidator"&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="http://localhost/CalcIISHost/mex"/&gt;
          &lt;add baseAddress ="net.tcp://localhost:808/CalcIISHost/CalcService"/&gt;
        &lt;/baseAddresses&gt;
      &lt;/host&gt;
      &lt;endpoint address ="" binding ="netTcpBinding" bindingConfiguration="tcpWithMessageSecurity" contract ="Contracts.ICalc"&gt;&lt;/endpoint&gt;
      &lt;endpoint address ="net.tcp://localhost:5001/CalcIISHost/mex" binding ="mexTcpBinding" contract ="IMetadataExchange"&gt;&lt;/endpoint&gt;
    &lt;/service&gt;
  ...
  &lt;behavior name="CustomValidator"&gt;
        &lt;serviceCredentials&gt;
          &lt;userNameAuthentication
            userNamePasswordValidationMode="Custom"
            customUserNamePasswordValidatorType="WCFClasses.CustomUserNameValidator, WCFClasses"/&gt;
          &lt;serviceCertificate
            findValue="localhost"
            x509FindType="FindBySubjectName"
            storeLocation="CurrentUser"
            storeName="My" /&gt;
        &lt;/serviceCredentials&gt;
        &lt;serviceMetadata httpGetEnabled ="true"/&gt;
      &lt;/behavior&gt;
  ...
  &lt;netTcpBinding&gt;
      &lt;binding name="tcpWithMessageSecurity"  sendTimeout="00:05:00" receiveTimeout="00:05:00"&gt;
        &lt;security mode="Message" &gt;
          &lt;message clientCredentialType="UserName"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/netTcpBinding&gt;
  </code></pre>
  
  <p>Any ideas what have i done wrong?</p>