Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / WCF

WCF NetTcp Binding

4.94/5 (9 votes)
28 Jan 2014CPOL3 min read 71.3K  
Optimize Your WCF Performance By NETTCP

NetTcp binding is based on Transmission Control Protocol. This is the most efficient binding and intended to be used in service to service communication in an intranet environment. The NetTcpBinding generates a run-time communication stack by default, which uses transport security, Transmission Control Protocol for message delivery, and a binary message encoding. Use this binding when you want to provide a secure and reliable binding environment for .NET-to-.NET cross-machine communication. NetTcpBinding is the equivalent of .NET Remoting in .NET 3.0, with the advantage that it is easier to code.

On the other hand, HttpBinding is based on HTTP protocol. It is compatible with Web Service Technology and SOAP standard, which are heavier than Transmission Control Protocol.

Characteristics And Limitations

  • It can only be consumed by WCF-enabled clients.
  • Transport security is turned on by default.
  • The service can be hosted in IIS 7.0 or later.
  • It supports the WS* stack, including reliable messaging, message security, and secure transactions.
  • It supports only intranet environment where the firewall configuration can be controlled.

Key Performance Areas

  • Increases in throughput of data notifications a client application can receive from the server
  • Allows more clients to be connected concurrently to the server
  • Reduces the Bandwidth utilization

Useful posts to learn more about NetTcp Binding and its advantages:

NetTCP Binding Configurations

XML
<system.serviceModel>
<services>
<service name="MyServiceNamespace.SSM">
<endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="MyServiceNamespace.ISSM"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="ultra"
     maxBufferPoolSize="2147483647"
     maxBufferSize="2147483647"
     maxConnections="2147483647"
     maxReceivedMessageSize="2147483647"
     portSharingEnabled="false"
     transactionFlow="false"
     listenBacklog="2147483647">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

Deployment Steps

Step 1

A very first step is to let the IIS support netTcp Binding, by default IIS only supports HTTP or HTTPS to do that. First, we need to activate the WCF non-HTTP activation. Go to control panel > Program and Features > Turn Windows features on or off, then look for ‘Microsoft .NET Framework 3.5.1′ .

Image 1

Select both the options under the umbrella of 'Microsoft .NET Framework 3.5.1' .

Step 2

As Step 1 automatically unregisters the ASP.NET, you need to register it with IIS again. Go to Visual Studio Command Prompt and type 'aspnet_regiis -i'. This command will register the ASP.NET with IIS.

Image 2

Step 3

Now check these Windows services running. Go to Run > services.msc and look for the highlighted services. Start them if these are in Stopped state.

Image 3

Step 4

Now configure IIS to enable a website to use net.tcp port which is 808 by default. You can also change it to any other port you want. Make sure you don’t configure net.tcp to port 80 because it is being used by HTTP and you cannot have two protocols running on the same port. Open IIS and then go to your ‘Default Web Site’ and right click on it and then go to ‘Edit Bindings’. Select net.tcp option from dropdown list.

Image 4

Step 4.5

Now assign the port address to IIS to listen TCP requests. 808 is a default port but you can have any other port as well. Format is ‘port:ipaddress’ I use ’808:*’ and then click ok.

Image 5

Step 5

Now enable net.tcp protocol for your application in the IIS. Right click on your application in the IIS and then click on ‘Advanced Settings’ and look for property ‘Enabled Protocols’ and enter ‘net.tcp’. It is a comma-separated list so you can enable multiple protocols by separating them with a comma.

Image 6

Conclusion

Using netTcp binding helps improve your application performance up to 80%. There are some links earlier in this post where you can check performance statistics of netTcp binding. Performance is one of the considerations of using netTcp binding. There are many more advantages to use this binding such as reliable messaging, port sharing, controlled firewall configuration and cross-machine communication.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)