Sunday, April 28, 2013

Hosting netTcp WCF Service in WAS

Code Download.

For this post I'm using Windows 8, but these steps should work in Windows 7 and Server 2008 also.

Some searching produced a MSDN post showing some commands that need to be executed if you're running Windows 7 or Server 2008. However these are not necessary in Windows 8.

"%WINDIR%\Microsoft.Net\Framework\v4.0.30319\aspnet_regiis" –i –enable

Running this command in Windows 8 returns:

Microsoft (R) ASP.NET RegIIS version 4.0.30319.17929
Administration utility to install and uninstall ASP.NET on the local machine.
Copyright (C) Microsoft Corporation.  All rights reserved.
Start installing ASP.NET (4.0.30319.17929).
This option is not supported on this version of the operating system.  Administr
ators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Win
dows Features On/Off" dialog,  the Server Manager management tool, or the dism.e
xe command line tool.  For more details please see
Finished installing ASP.NET (4.0.30319.17929).
The post also recommended running:
"%WINDIR%\Microsoft.Net\Framework\v4.0.30319\ServiceModelReg.exe" -r  
Which also returns something similar:

Microsoft (R) WCF/WF registration tool version
Copyright (c) Microsoft Corporation.  All rights reserved.

Administration utility that manages the installation and uninstallation of
WCF and WF components on a single machine.

[Error]This tool is not supported on this version of Windows. Administrators sho
uld instead install/uninstall Windows Communication Foundation features using th
e 'Turn Windows Features On/Off' dialog, or the dism command line tool.
Install IIS and WAS Hosting components with add/remove windows features:

After completing this re-running the aspnet_regiis command above still returns the same response, so this is definitely not necessary in Windows 8.

The above installation of windows components has automatically registered net.tcp with IIS.

Previously under Windows 7 running the following command would have been necessary:
%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']

You can check to ensure net.tcp has been enabled for the default web site by opening IIS and looking at the default web site bindings: (If you have multiple sites hosted inside IIS then net.tcp can be added manually using this dialog also)

Open the advanced settings for your virtual directory and ensure net.tcp is an enabled protocol, if not just type it in.

The new service virtual directory will use the "Default App Pool" this will be using the Framework v4, in integrated mode.  If your default app pool is different, create a new app pool with these settings.

You should now be able to browse to the service using a browser.  (The web.config of the service has enabled <serviceMetadata httpGetEnabled="true"/>)

Since httpGetEnabled is on, using the WcfTestClient.exe you can add the service using "http://localhost/WasTcpDemo/CalculatorService.svc".
However, the client config the tool has generated only allows communication with net.tcp for invoking service operations.
Given the web.config also allows for obtaining metadata over net.tcp you can also add the service using the address "net.tcp://localhost/WasTcpDemo/CalculatorService.svc".

Once the Test Client has added the service, you can remove the serviceMetadata element and the MetadataExchange binding to ensure net.tcp communications without exposed metadata.


One Time setup:
This post was based on the MSDN Example:


  1. Using the two command lines mentioned on windows 7 all works fine. Running the command's multiple times has no detrimental effort, so can be incorporated into an installer.

  2. On a 64 bit OS, you'll need to run ServiceModelReg.exe from the %WINDIR%\Microsoft.NET\Framework64\v4.0.30319 folder instead of the "Framework" folder.