title: How to configure net.tcp binding for client in WCF
body: <p>I'm new to WCF services and I have created a same application using WCF. Please see below the basic code:</p>
  
  <p><code>IService1.cs</code>:</p>
  
  <pre><code>[ServiceContract]
  public interface IService1
  {
      [OperationContract]
      string GetData(int value);
  
      [OperationContract]
      CompositeType GetDataUsingDataContract(CompositeType composite);
  
      [OperationContract]
      String WelComeMessage(String name);
  }
  </code></pre>
  
  <p><code>Service1.svc.cs</code>:</p>
  
  <pre><code>public class Service1 : IService1
  {
      public string GetData(int value)
      {
          return string.Format("You entered: {0}", value);
      }
  
      public CompositeType GetDataUsingDataContract(CompositeType composite)
      {
          if (composite == null)
          {
              throw new ArgumentNullException("composite");
          }
  
          if (composite.BoolValue)
          {
              composite.StringValue += "Suffix";
          }
  
          return composite;
      }
  
      public String WelComeMessage(String name)
      {
          return String.Format("{0}, Welcome to http://www.csharptutorial.in", name);
      }
  }
  </code></pre>
  
  <p>and <code>web.config</code>:</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
   &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I want to make this service <code>net.tcp</code> binding ready, can anyone help me to understand where to declare the <code>net.tcp</code> binding and how to consume this service using <code>net.tcp</code> binding?</p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>I have updated the Server configuration file (in WCF service configuration file) below:</p>
  
  <pre><code>&lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="DemoWCF.Service1"
                 behaviorConfiguration="MyServiceBehavior"&gt;
          &lt;endpoint name="NetTCPBinding_IService1Client"
                    address="net.tcp://localhost:10109/Service1.svc"
                    binding="netTcpBinding"
                    bindingConfiguration="EndPointConfiguration"
                    contract="DemoWCF.IService1" /&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="net.tcp://localhost:10109/Service1" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;bindings&gt;
        &lt;netTcpBinding&gt;
          &lt;binding name="NetTCPBinding_IService1"  sendTimeout="00:01:00"&gt;
            &lt;security mode="None" /&gt;
          &lt;/binding&gt;
        &lt;/netTcpBinding&gt;
      &lt;/bindings&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="MyServiceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="false"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
            &lt;dataContractSerializer maxItemsInObjectGraph="65536" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And below is the client side code:</p>
  
  <pre><code>static void Main(string[] args)
          {
              try
              {
                  Service1Client service1Client = new Service1Client("NetTCPBinding_IService1");
                  Console.WriteLine(service1Client.WelcomeMessage("Hello from net.tcp"));
                  Console.ReadLine();
              }
              catch (Exception ex)
              {
                  throw ex;
              }
  
          }
  </code></pre>
  
  <p>But it throws an exception:</p>
  
  <p><strong>Exception:</strong> You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint.</p>
  
  <p><strong>Inner Exception:</strong></p>
  
  <p>{"Expected record type 'PreambleAck', found '72'."}</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>I have hosted my WCF service in the IIS 7.5 and added net.tcp binding using edit binding... option. as well as from command line:</p>
  
  <p><strong>set site "DemoWCF" -+bindings.[protocol='net.tcp',bindingInformation='10108:*']</strong></p>
  
  <p>Web service shows running perfectly.</p>
  
  <p><img src="https://i.stack.imgur.com/D6wC9.png" alt="enter image description here"></p>
  
  <p>But consuming this WCF service at client side still the same exception.</p>
  
  <p><strong><em>Client Code:</em></strong></p>
  
  <pre><code>try
  {
      ServiceReference1.Service1Client s = new ServiceReference1.Service1Client();
      Response.Write(s.WelcomeMessage("Hello from net.tcp"));
      Response.End();
  }
  catch (Exception ex)
  {
      Response.Write(ex);
      Response.End();
  }
  </code></pre>
  
  <p><strong><em>Client Web.config:</em></strong></p>
  
  <pre><code>&lt;bindings&gt;
    &lt;netTcpBinding&gt;
      &lt;binding name="NetTCPBinding_IService1Client"&gt;
        &lt;security mode="None" /&gt;
      &lt;/binding&gt;
    &lt;/netTcpBinding&gt;
  &lt;/bindings&gt;
  &lt;client&gt;
    &lt;endpoint address="net.tcp://localhost:10108/Service1.svc" binding="netTcpBinding"
      bindingConfiguration="NetTCPBinding_IService1Client" contract="ServiceReference1.IService1"
      name="NetTCPBinding_IService1Client" /&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p><strong>Same Exception:</strong> You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint.</p>
  
  <p><strong>Inner Exception:</strong></p>
  
  <p>{"Expected record type 'PreambleAck', found '72'."}</p>
  
  <p><strong>Edit 3:</strong></p>
  
  <p>Tried consuming the service by below code too:</p>
  
  <pre><code>IService1 vService;
  
                  NetTcpBinding b = new NetTcpBinding();
                  b.Security.Mode = SecurityMode.Message;
                  b.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
  
                  EndpointAddress vEndPoint = new EndpointAddress("net.tcp://localhost:10108/Service1/");
                  ChannelFactory&lt;IService1&gt; cf = new ChannelFactory&lt;IService1&gt;(b, vEndPoint);
  
                  vService = cf.CreateChannel();
  
                  try
                  {
                      Response.Write("Result from the system " + vService.WelcomeMessage("Hello"));
                  }
                  catch (Exception ex)
                  {
                      Response.Write("Error Occured while connection establish to " + vEndPoint.Uri.ToString());
                  }
                  Response.End();
  </code></pre>
  
  <p>Still getting the same exception, Can anyone help?</p>