Click here to Skip to main content
12,821,041 members (33,484 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 6 Jan 2012

NetTcpBinding Configurations for WCF and Silverlight Application on IIS 7

, 6 Jan 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
NetTcpBinding Configurations changes for WCF and Silverlight Application on IIS 7 in Windows 7


In this article, I would like to give a brief idea on using NetTcpBinding with Silverlight application and hosting configuration to be done on IIS 7.

Note: Only IIS7 has support for net.tcp binding.

One of the most important features in Silverlight 4 is the introduction of NetTcpBinding support; we can communicate with a WCF service using net.tcp protocol.

Advantages of using NetTcpBinding

  • Performance: Silverlight applications using NetTcpBinding communicates with WCF service in your intranet zone. Performance of NetTcpBinding compared to HTTP polling duplex is the key reason to consider using the WCF net.tcp protocol in duplex communication scenarios. NetTcpBinding offers major performance gains when compared to httpPollingDuplex on these parameters:
    • Increase in throughput of data notifications a client application can receive from the server.
    • Increase in the maximum number of connected clients the server can support concurrently.
  • Duplex Communication: Supports Duplex communication between client and service.
  • IDE Integration: Net.tcp protocol is well integrated with the Add Service Reference feature in Visual Studio 10. A WCF service proxy to a WCF service exposed using the net.tcp binding can be easily generated for a Silverlight 4 client application. Net.tcp protocol comes with Silverlight configuration support (ServiceReferences.ClientConfig), so the details of the binding, including service address, can be changed without recompiling the application.
  • Improved library factoring to help optimize the Silverlight application (XAP) size. Applications that utilize only request/response exchange patterns using WCF have all the required components available in Silverlight core. Applications that require duplex message exchange patterns must include the System.ServiceModel.Extensions.dll in the XAP, as well as one or both of System.ServiceModel.NetTcp.dll and System.ServiceModel.PollingDuplex.dll, depending on the protocol the application is using. System.ServiceModel.Extensions.dll contains functionality common for all duplex communication scenarios. System.ServiceModel.NetTcp.dll supports the WCF net.tcp protocol and System.ServiceModel.PollingDuplex.dll the HTTP polling duplex protocol. When a proxy is created in a Silverlight 4 project using the Add Service Reference feature of Visual Studio 10, appropriate library references will be added to the project depending on the actual protocols the WCF service exposes.

Note: NetTcpBinding is subject to TCP port limitations, Silverlight applications with NetTcpBinding can run only on ports 4502-4534.

Configuring web.config for Silverlight Application

  1. Create a new Visual Studio solution which consists of a Silverlight 4 application and website to serve the application. Once we have the application in place, we need to consume the WCF service. To do this, we need to configure the (web.config) file of the Silverlight web application. By default, the code in web.config looks as shown below:
    <?xml version="1.0"?>
      <compilation debug="true"/>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />

    We need to change the configuration to the following:

            <binding name="InsecureTcp" receiveTimeout="Infinite">
              <security mode="None"/>                                    Net Tcp
            </binding>                                                   Declaration.
       <service behaviorConfiguration="GridUIFinal1._0.Web.IControllerServiceBehavior" 
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="InsecureTcp" 
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
     <add     baseAddress="net.tcp://localhost:4502/

Configuring IIS for Silverlight Application

The configuration changes for hosting the WCF and Silverlight application on IIS on Windows 7 is as follows:

  1. Install IIS in the machine

    To install IIS, click on Start->Run and type appwiz.cpl in the Command window and press Enter. Now click on Turn Windows features on/off.

  2. Enable Internet Information Services and ensure that all the subfolders under IIS are checked and Click on Ok. This will install IIS on your machine.

    Fig.1 Install IIS
  3. WCF services with net tcp binding inside IIS are hosted on Windows Activation Services (WAS). To enable WAS hosting on IIS, a few configurations are needed to be done. You must enable Windows Communication Foundation Non-Http Activation on IIS.

    Fig.2 Install WCF Non-HTTP Activation
  4. Go to the solution explorer of the project->Right click on the Silverlight web project-> Click on Properties. Then modify the web site configuration to run under IIS by selecting "Use Local IIS Web server". It will auto fill a project URL and then Click on 'Create Virtual Directory' to set up the application in IIS.

    Fig.3 Modify web site to run under IIS.

Configuring Properties for the Hosted Application

  1. Go to Inetmgr->Project/Website->Advanced Settings.

    Fig.4 IIS Settings

    Change the ASP.NET configuration to the version of the .NET Framework in which the WCF Service is built.

    Fig.5 Change Application Pool.

    Fig.6 Set Application Pool to ASP.NET v4.0 to use Framework4

    Also add the net.tcp protocol in the Enabled Protocols under Behavior section as shown below:

    Fig.7 Enable net.tcp Protocol
  2. Go to Inetmgr->Project/Website->Edit Bindings.

    Fig.8 Edit Bindings
  3. In Site Bindings->Edit.

    Fig.9 Click on Edit to add port number
  4. Add the Port on Binding Information i.e., 4502 as we already know Net Tcp binding supports ports(4502-4535) shown below: click on Ok.

    Fig.10 Adding the port number.
  5. Make sure that the Net Tcp Listener Adapter is started and running in Services.msc:

    Fig.11 Check for Net Tcp Adapters in Services.msc

Note: After this configuration, you will be able to access your application either using IpAddress of server or using machine name. The best way to configure is use machine name/ IpAddress in both places (IIS and web.config).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sanath S. Shenoy
Software Developer (Senior)
India India
you could also follow up my articles on my personal blog

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Ralph Shillington27-Jul-13 10:34
memberRalph Shillington27-Jul-13 10:34 
QuestionConsuming external wcf service Pin
adrian lewis19-Feb-13 3:11
memberadrian lewis19-Feb-13 3:11 
GeneralMy vote of 1 Pin
Nick9873-Oct-12 6:10
memberNick9873-Oct-12 6:10 
QuestionActually were you able to call net.tcp service from Silverlight ? Pin
joygk30-May-12 4:45
memberjoygk30-May-12 4:45 
AnswerRe: Actually were you able to call net.tcp service from Silverlight ? Pin
fun.arsh22-Jun-12 15:17
memberfun.arsh22-Jun-12 15:17 
QuestionI got errors Pin
stanywhite24-May-12 21:51
memberstanywhite24-May-12 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 6 Jan 2012
Article Copyright 2012 by Sanath S. Shenoy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid