Monday, May 14, 2012

Hosting WCF Service on IIS 7 with nettcp bindings

this blog will demonstrate how to host nettcpbing enabled wcf service on IIS and after IIS 7.0 releases, it allows to host the tcp binding enabled wcf service.

The nettcpbinding is based on TCP ( Transmission Commision Protocol), this protocal is very efficient in service to service communication and it supports the reliable message delivery and binary message encoding.
  1. Configure nettcpbinding endpoint 
  2. Configure IIS 7.0

Configuring nettcpbinding endpoint :
add the nettcpbinding endpoint in the WCF config file.

<service behaviorConfiguration="MyBehavior" name="Wcf_Tcp_Service.Service1">
<endpoint address=""  binding="netTcpBinding" bindingConfiguration="portSharingBinding"  name="MyServiceEndpoint" contract="Wcf_Tcp_Service.IService1">
<dns value="localhost" />
<endpoint address="mex" binding="mexTcpBinding"name="MyServiceMexTcpBidingEndpoint" contract="IMetadataExchange" />
<add baseAddress="net.tcp://localhost:808/WCFNetTcp/Service1.svc" />

the nettcpbnding endpoint is defined, which use nerTcpBinding and “portSharingBinding” bindingConfiguration which is defined as below :
<binding name="portSharingBinding" portSharingEnabled="true"/>
<binding name="mexTcp" portSharingEnabled="true">
   <security mode="None" />

The portSharingEnabled Property control whether net.tcp:// port sharing is enabled for the service being configured with this binding.

Note: Port 808 in the end point base address would also be required while performing the configuration settings in IIS 7.0. If you wish to change the port here, remember to perform the same in IIS 7.0 as well.

Configuring IIS 7.0 - 

1.       Under the sites node right click the website you wish to create your WCF Service virtual directory, and select the “Add Application” option,  give your application an alias name and path where the service code resides.  In the Application pool select ASP.NET v4.0 as the application pool and click OK.

2.       Right click the website and select the Edit binding option, this opens up the site bindings dialog. Make sure net.tcp binding type is present with port as 808, if not, go ahead and add a net.tcp binding using the dialog Add button.

3.       Right click the virtual directory created in the first step, select Manage Application -> Advance Settings. In the Advance settings dialog update the Enabled protocols property to “http,net.tcp” and click OK.

4.       Go to the IIS root and select the Features view. In the features “IIS” panel, double click the “ISAPI and CGI Restrictions” feature. In the “ISAPI and CGI Restrictions” window that opens, right click on all the ASP.NET 4.0 entries and select “Allow”.

5.       Go to Windows -> run and type services.msc to open the services control panel. Find the services with the name “Net.Tcp Port Sharing Service” and “Net.Tcp Listener Adapter” and start them.

6.       Add reference of your WCF service to your client application and check whether proxy classes are getting created, if yes, we are done.

Note: If you are unable to find an Application pool with the name ASP.NET v4.0 go ahead and create one. Under IIS root, right click Application Pool node and select “Add Application Pool”. In the dialog give name of the pool as “ASP.NET v4.0”, select .NET Framework 4.0 and click OK.


1.       Windows firewall on the service hosting box is not blocking the TCP port/communication.

2.       To find whether the configured port is available or not, open cmd and type “netstat –a” to find the active ports.


SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...