Gal Ratner
Gal Ratner is a Techie who lives and works in Los Angeles CA and Austin TX. Follow galratner on Twitter Google
Setting up a netTcpBinding enabled WCF Service in IIS 7

netTcpBinding is a secure, reliable binding suitable for cross-machine communication. It uses TCP for message delivery along with a binary message encoding which makes is faster than HTTP based bindings such as WSHttpBinding and BasicHttpBinding.

Hosting a netTcpBinding service in IIS 7 is simple, however it requires several steps.

1. Add Non-HTTP Activation: from the Add Features Wizard select .NET Framework 3.0 Features and add Non-HTTP Activation

2. Make sure the Net.TCP services are running:  netTcpBinding uses two windows services. NetTcpActivator -  Receives activation requests over the net.tcp protocol and passes them to the Windows Process Activation Service and NetTcpPortSharing - provides ability to share TCP ports over the net.tcp protocol. This service enables net.tcp ports to be shared across multiple user processes which will make it easier to manage open ports in your network.

3. In IIS navigate to your website and select Advanced Settings from the right menu. Add net.tcp to the Enabled Protocols.

4. In IIS select Bindings from the right menu. Add a new net.tcp binding with the port you wish to use. I used port 808 so my Binding information looks like 808:*

5. From now on the system is ready to run netTcpBinding so you can now add it to web.config:

<service behaviorConfiguration="MyBehavior"
<endpoint address="" 
<dns value="localhost" />

<endpoint address="mex" 
  contract="IMetadataExchange" />
<add baseAddress="net.tcp://MyServerIPAddress:808/MyService.svc" />
<behavior name="MyBehavior">
  <serviceMetadata httpGetEnabled="false" />
  <serviceDebug includeExceptionDetailInFaults="false" />
<binding name="portSharingBinding" portSharingEnabled="true"/>

A mexTcpBinding endpoint is needed in order to use IMetadataExchange over TCP. IMetadataExchange exposes methods used to return metadata about a service. Now the  service should be up and running so from Visual Studio just add a Service reference. Point the reference to: net.tcp://MyServerIPAddress:808/MyService.svc. It should generate the following configuration:

<binding name="MyServiceEndpoint" closeTimeout="00:01:00"
 openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
 transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
 hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
 maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
 maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
 enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
<endpoint address="net.tcp://MyServerName/MyService.svc"
 binding="netTcpBinding" bindingConfiguration="MyServiceEndpoint"
 contract="MyNamespace.IMyService" name="MyServiceEndpoint">
<dns value="localhost" />

Now you are ready to use the service from the client you generated:

using (MyServiceClient client = new MyServiceClient())

That’s it. You should be able to communicate with your service faster and more efficiently than any HTTP based binding.

Shout it

Posted 8 Oct 2010 6:48 PM by Gal Ratner
Filed under: ,

Powered by Community Server (Non-Commercial Edition), by Telligent Systems