Friday, February 24, 2012

WCF NetTcp in IIS

Today I will make a short demo about hosting wcf services with nettcpbinding in iis.
There are cases when is more suited for your service to use a nettcpbinding for different reasons: speed, reliability, etc.
But in this case you are limitted to choose the hosts of your service from console app, windows service. So what if you want to host your service in iis and still expose nettcpbindings ?

So here are a few stept that must be done before we can use our service. For a more in-depth description check this post IIS 7.0 and WAS

Step 1. Enable Non-Http protocols
Go to Control Panel->Programs->Turn Windows features on/off and under .NetFramework 3.5.1 be sure to tick "Non-Http activation" (remember that iis supports only http)

Step 2. Enable WAS and PortSharing.
The previous step will make available some services (wcf services by the way) that will help us. So go now in your services list: Task Manager->Services tab and be sure that the following services are running:

WAS - is the Windows process activation service
NetTcpPortSharing -  is the WCF TCP port sharing service. It implements a centralized TCP listener so that multiple processes can listen on the same TCP port. This service is available even if IIS 7.0 is not installed.
NetTcpActivator - is the WCF TCP Activation Service. It communicates TCP activation requests to WAS.
Step 3. Create a WCF Service with a NetTcpBinding and create the endpoints.

Create the binding in the bindings tag, and then create 2 endpoints. One for your contract and one mex.
Note: If you don't create the mex endpoint, you won't be able to add a reference in your project.
Step 4. Publish the service in iis and configure it

Right click on the service->Publish. Be sure to tick 'Mark as IIS application'
In IIS, expand your newly created application, go in content view and browse your service. You will get this error:
This tells us that currently we don't have support for tcp protocol so here is what you have to do in order to eneable it: in iis, right click on application->Manage Application->Advanced Settings and add "net.tcp" next to http and then click ok.
 Now the error should be gone
Step 5. Add a reference to your project
And that's it :).


  1. thanks, but link download dead

    1. I tried the download link few moments ago and seems to be working. I can send it to your email address.

  2. Hello there, thanks for this guide over net.tcp binding using service publishing. I am trying to do the same thing but with a little difference, I want to publish it to my remote server. Then I will be able to consume that service from my client applications. But I am having troubles doing so. I couldn't manage to get the servers dns into wsdl file properly, it takes computers name like this in links http://win-rhkt30stjd7/Broadcastor/BroadcasterService.svc?wsdl which is not useful or correct at all. If you can give me any hint on this problem I will be appreciated.

    1. Hi, I'm not sure if I understood correctly your problem but it seems a connectivity issue ?!?
      First of all how do you get 'servers dns into wsdl file' ? WSDL is almost always auto generated. So I'm not sure if you're trying to edit the file or to get the right url in WSDL.
      If this is the case you could try :
      1. Put the Real IP of your server instead of the name
      2. Create a static WSDL, so whenever a request for the WSDL or Metadata comes in, this static WSDL will be provided instead.