This is my first time implementation of TCP with WCF. For completing this I had to undergo multiple steps. I faced multiple issues in different stages.
I want to present the steps to implement TCP in WCF with the Windows Activation Service (WAS) of IIS 7. Making the service consumable through TCP protocol involves the following steps.
Note: I use Windows 7 and the paper talks about steps in Windows 7. However it may be the same in Windows Vista as well.
1. Configure WAS
By default IIS is not ready for offering us the TCP support. We need to configure the Windows Activation Services to enable the support.
To do this, click Start –> Control Panel –> Programs and Features
Here we can find “Turn windows features on or off”. On clicking this, we’ll get the following pop up.
Expand the Microsoft.NET Framework 3.5.1 (or 3.0), check the “Windows Communication Foundation Non-HTTP Activation” and press OK. This will configure the IIS for supporting Non-HTTP protocols (net.tcp, net.pipe, net.msmq)
2. Turn on Windows NT services
To support Non-Http protocols, IIS 7.0 and WAS use a set of Windows NT services.
Net.Tcp Listener Adapter
Net.Tcp Port sharing service
To enable these services, click –> Start –> Administrative Tools –> Services (Or simply, Start –> All Programs –> Accessories –> Run and type Services.msc)
In the resulting Services windows, we can find these services.
By default these services are Disabled. To enable them, double click on each service and set the start up type as Automatic. (Select Automatic in the Startup type drop down and select Apply)
Once the service is enabled, you can right click on the service and select Start to start the service.
Note: For the other Non-HTTP protocols, net.pipe, net.msmq, we have the following services.
Net.Pipe Listener Adapter
Net.Msmq Listener Adapter
However Net.Msmq can’t be started directly. It requires extra configuration through “Programs and Features –> Turn windows features on or off” before starting up the service.
3. Enable TPC for the web site
Having enabled the support for TCP protocol, the next step is to enable the protocol in the web site.
I wanted to host my application in the Default Web Site in IIS 7.
To do this, click Start –> type IIS or inetmgr in the Start Menu’s search text box.
This will show up the “Internet Information Manager” application. Open the application.
Expand root node on the left pane, Expand the Sites, locate the Default Web Site (or any other site of your preference) in the list.
Right click on the Site –> Edit Bindings
By default http is enabled in all the Sites.
To enable TCP protocol, select the Add button. In the popup window, select the Type as net.tcp, and fill the binding information with as follows.
<prefered Tcp Port number>:*
On selecting Ok. You are enabling the tcp on the site.
4. Enable TCP for the Web Application
If the site is representing the web application, we should be good with the previous step. But in my case, I have an application (VersionTolerance) inside the Default Web Site.
So it is necessary to do an additional step of enabling the TCP protocol at the application level as well.
To do this, click and select the Web application inside the web site. (VersionTolerance inside the Default Web Site).
In the far right of the window, we can find “Manage Application”. Under this select Advanced Settings.
In the Advanced Settings window, Enabled Protocols option would have the value “http” by default. Now edit that value to show “http,net.tcp” (Careful: there is no space in the entire text)
With this step we are done with the configuration part of tcp protocol.
However I have faced some more obstacles in achieving the tcp communication.
5. Set Framework Version
When I tried to browse to WSDL of my service, the browser threw the following error message.
Parser Error Message: Unrecognized attribute ‘targetFramework’. Note that attribute names are case-sensitive.
Line 36: <connectionStrings />
Line 37: <system.web>
Line 38: <compilation debug="true" targetFramework="4.0">
Line 39: </compilation>
Line 40: <!--
Though this issue is not related to the set up of TCP protocol, it is inevitable.
When a web site is created, it would be associated with an application pool. An application pool can be understood as group of Web sites. Grouping web sites in the form of App pools give a convenient way for Administering the sites, underlying applications and their worker processes.
By default the “Default Web Site” site is created to support .Net framework version 2.0.
The root cause of the error message I faced was exactly this. I have to move the supporting frame work as 4.0 since a WCF application can be created with a framework 3.0 or above.
To change the framework version in the app pool, select the Application Pools under the root node of IIS 7. Double click the app pool that your site is associated with. In my case I have chosen DefaultAppPool.
In the Edit Application Pool dialog, select the .Net Framework Version to .Net Framework v4.x.
With all these step done, we are good to deploy the tcp service in IIS. Though I was talking about the tcp protocol throughout the paper, the same set of steps are applicable for net.pipe protocol as well.