Click here to Skip to main content
15,867,834 members
Articles / Web Development / IIS

NetTcpBinding Configurations for WCF and Silverlight Application on IIS 7

Rate me:
Please Sign up or sign in to vote.
3.20/5 (5 votes)
6 Jan 2012CPOL4 min read 46.8K   18   6
NetTcpBinding Configurations changes for WCF and Silverlight Application on IIS 7 in Windows 7

Introduction

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
    <?xml version="1.0"?>
    <configuration>
     <system.web>
      <compilation debug="true"/>
      </system.web>
    <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="">
                        <serviceMetadata httpGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
        </system.serviceModel>
    </configuration>

    We need to change the configuration to the following:

    XML
    <bindings>
          <netTcpBinding>
            <binding name="InsecureTcp" receiveTimeout="Infinite">
              <security mode="None"/>                                    Net Tcp
            </binding>                                                   Declaration.
          </netTcpBinding>
    </bindings>
    <services>
       <service behaviorConfiguration="GridUIFinal1._0.Web.IControllerServiceBehavior" 
    	name="GridUIFinal1._0.Web.ControllerService">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="InsecureTcp" 
    	contract="GridUIFinal1._0.Web.IControllerService"/>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
    <host>
     <baseAddresses>
     <add     baseAddress="net.tcp://localhost:4502/
    		DuplexSilverlightExamples.Web/TestService.svc">
     </add>
    </baseAddresses>
    </host>
    </service>
    </services>

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.

    Image 1

    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.

    Image 2

    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.

    Image 3

    Fig.3 Modify web site to run under IIS.

Configuring Properties for the Hosted Application

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

    Image 4

    Fig.4 IIS Settings

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

    Image 5

    Fig.5 Change Application Pool.

    Image 6

    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:

    Image 7

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

    Image 8

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

    Image 9

    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.

    Image 10

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

    Image 11

    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).

License

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


Written By
Software Developer (Senior)
India India
you could also follow up my articles on my personal blog

www.sanathshenoy.blogspot.com

Comments and Discussions

 
GeneralMy vote of 1 Pin
Ralph Shillington27-Jul-13 9:34
Ralph Shillington27-Jul-13 9:34 
QuestionConsuming external wcf service Pin
adrian lewis19-Feb-13 2:11
adrian lewis19-Feb-13 2:11 
GeneralMy vote of 1 Pin
Nick9873-Oct-12 5:10
Nick9873-Oct-12 5:10 
QuestionActually were you able to call net.tcp service from Silverlight ? Pin
Joy George K30-May-12 3:45
professionalJoy George K30-May-12 3:45 
AnswerRe: Actually were you able to call net.tcp service from Silverlight ? Pin
fun.arsh22-Jun-12 14:17
fun.arsh22-Jun-12 14:17 
QuestionI got errors Pin
stanywhite24-May-12 20:51
stanywhite24-May-12 20: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.