This post will walk you through setting up and running a WCF service using NetTcp binding on Windows Process Activation Service (WAS). WAS is a new feature of IIS 7.0 and makes it possible to host WCF services beyond HTTP and without installing the whole of IIS components. If you are interacting with services within the same infrastructure, you might opt to use NetTcp over HTTP binding; net.tcp being faster since your soap message is not wrapped inside a HTTP request. In this example I have a Stockmarket application with a net.tcp endpoint and a http mex endpoint to expose the metadata. I will be hosting it under root "Default Web Site/StockMarket"
1. The first step is you configure your WCF service to have NetTcp binding.
<system.serviceModel> <services> <service name="StockMarket.StockService" behaviorConfiguration="mexBehavior"> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:8000/StockMarket"/> <add baseAddress="http://localhost/StockMarket"/> </baseAddresses> </host> <endpoint address="" binding="netTcpBinding" contract="StockMarket.IStock"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="mexBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel>
2. The next step is to set up your system to host non-HTTP activation endpoints. For that you may follow this MSDN post. Specifically these are the steps you need to perform:
Install WCF non-activation endpoints
To configure the WAS to support TCP activation
To support net.tcp activation, the default Web site must first be bound to a net.tcp port. You can do this by using Appcmd.exe, which is installed with the IIS 7.0 management toolset. In an administrator-level Command Prompt window,run the following command.
%windir%\system32\inetsrv\appcmd.exe set site "Default Web site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']
This command adds a net.tcp site binding to the default Web site listening on TCP port 808 with any host name. Although all applications within a site share a common net.tcp binding, each application can enable net.tcp support individually.
To enable net.tcp for the application, run the following command from an administrator-level command prompt.
%windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/<WCF Application>" /enabledProtocols:http,net.tcp
This command enables the /<WCF Application> application to be accessed using both http://localhost/<WCF Application> and net.tcp://localhost/<WCFApplication>.
3. Once this is done, publish your service and navigate to http://localhost:8000/StockMarket/StockService.svc to get the metadata. You may encounter an error message as follows.
Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089′.
This error occurs if you install .Net 4.0 on IIS and enable .Net 3.0 or 3.5 features. This error also occurs if you run on .net 4.0 application pool. To resolve this issue, run the following from command line:
The aspnet_regiis.exe file can be found in either "%windir%\Microsoft.NET\Framework\v4.0.30319" (x86) or "%windir%\Microsoft.NET\Framework64\v4.0.30319" (x64)
That's it. You should be now running your net.tcp based WCF service on IIS WAS. Happy coding. :)
If you still can't connect, make sure that the "Net.<*TCP/PIPE/etc*> Listener Adapter" service is running in Services management console. This is used by WAS to receive any request on named <*TCP/PIPE/etc*>.