2

I am trying to host a WCF Service with Net TCP bindings in IIS 7 / Win 7. The service is hosted and i can add a reference to it in my client application.

Here is the service configuration file:

  <configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.0" />

    </system.web>
    <system.serviceModel>
      <bindings>
        <netTcpBinding>
          <binding name="InsecureTcp" portSharingEnabled ="true">
            <security mode="None">
              <transport clientCredentialType="None" protectionLevel="None" />
            </security>
          </binding>
        </netTcpBinding>
      </bindings>
      <services>
        <service name="ApplicationProcessService">
          <endpoint address="" binding="netTcpBinding" bindingConfiguration="InsecureTcp"
            name="NetTCP_Port10000" contract="IApplicationProcess" />
          <endpoint address="mex" binding="mexHttpBinding" name="mexNetTCP_Port10000"
            contract="IMetadataExchange" />
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior name="">
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="true" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
        <baseAddressPrefixFilters>
        </baseAddressPrefixFilters>
      </serviceHostingEnvironment>

    </system.serviceModel>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

  </configuration>

And here is the configuration generated at client when I add the reference:

<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTCP_Port10000" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
            transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:10000/ApplicationProcess.svc"
          binding="netTcpBinding" bindingConfiguration="NetTCP_Port10000"
          contract="ApplicationProcessService.IApplicationProcess" name="NetTCP_Port10000" />
    </client>
  </system.serviceModel>
</configuration>

The problem is at run time, i get the following error:-

Could not connect to net.tcp://localhost:10000/AppServer.ApplicationProcess.svc. The connection attempt lasted for a time span of 00:00:02.0582058. TCP error code 10061: No connection could be made because the target machine actively refused it.

I have followed the steps described in http://www.singingeels.com/Articles/Duplex_WCF_Services_Hosted_in_IIS_Using_NetTcp.aspx

and created an inbound rule in my firewall allowing TCP communication on port 10000. I am not sure what am i missing. Any thoughts?

Apurv
  • 171
  • 4
  • 18
  • found similar question, but i am not making that mistake. [http://stackoverflow.com/questions/4820172/how-to-setup-wcf-net-tcp] – Apurv Aug 11 '11 at 15:47
  • Did you ever figure this out? http://stackoverflow.com/questions/16628382/setting-up-wcf-tcp-service-in-a-web-application – Niels Brinch May 25 '13 at 08:40

3 Answers3

2

The key here is is that you have enabled port sharing (PortSharingEnabled in your bindings) which requires that you run the TCP Port sharing service, which is not running by default in Windows. See this link: NetTcpBinding.PortSharingEnabled

Haukman
  • 3,726
  • 2
  • 21
  • 33
  • i added the PortSharingEnabled as i thought it might be the issue here, but didn't change any thing. I have the NetTcpPortSharing Service started under services.msc. – Apurv Aug 10 '11 at 23:47
  • ok. do a netstat -ban to see if 10000 is open, maybe it's bound to your local ip (and not all). Try to connect to your machine name/ip instead of localhost. – Haukman Aug 11 '11 at 00:05
  • `[FrameworkService.exe] TCP 0.0.0.0:10000 0.0.0.0:0 LISTENING` – Apurv Aug 11 '11 at 14:56
  • That looks correct. My guess is that you have some 3rd party firewall installed. – Haukman Aug 11 '11 at 21:13
  • McAfee Enterprise Antivirus. Don't See a setting for firewall in McAfee. – Apurv Aug 12 '11 at 11:15
  • McAfee may be the culprit. Can you try to telnet to localhost 10000 and see if you get the prompt or if it closes right away? – Haukman Aug 15 '11 at 16:05
  • I ran the `cmd (run as admin)` and then typed `telnet myIPAddress 10000`. The window goes blank for a while and then I can see `C:\Windows\System32`. I can presume that Telnet is not working. can you recommend a workaround? i can't disable McAfee, as it probably requires domain admin rights. – Apurv Aug 15 '11 at 20:11
  • If you get the prompt back (instead of a flashing cursor at the top of the screen) then you have something blocking you. Can you try this on another machine? Corporate IT like to block these things since some virus/adware-stuff likes to set up a local proxy to get all your internet traffic. By blocking local ports they aren't effective. But it's hard to confirm this, try on another machine first if available. – Haukman Aug 15 '11 at 20:52
  • maybe, for getting this to work on my dev machine, i will try to use a different port. I will also confirm with IT if that port is blocked. ... But then it confuses me a bit... i can set up the service with basicHttp binding on port 10000 and it works. I also tried hosting a normal windows service hosted net tcp service on 10000, and it works too. So somehow, i can't reason myself into believing that McAfee could be the cause. I just can't get my tcp service running on IIS. – Apurv Aug 16 '11 at 01:57
  • Ah, then I doubt it's a firewall, good information, but it's still very odd that telnet doesn't work. On the other hand, it could be WCF that accepts the connection, but something isn't right so it forces it closed right away. Maybe you can turn on full WCF tracing and see if you can see something? – Haukman Aug 16 '11 at 16:23
  • i am shelving this for a while. I will work on it the week after the next. have to catch up on other tasks... – Apurv Aug 20 '11 at 23:15
  • Thanks for your help. I am marking your answer as the right answer for your help. I deployed my code as-is to a Windows Server 2008, and it worked like a charm. However, on my Win 7, it still is a problem. We are using http bindings now for our Win 7 machines, and the code is being deployed to Windows Server 2008 with net.tcp bindings. – Apurv Oct 02 '11 at 05:01
  • ok, thanks, sorry I couldn't get the end result you expected. – Haukman Oct 03 '11 at 23:56
2

In addition to the Net.Tcp Port Sharing Service that was mentioned previously, you'll also need to enable and start Net.Tcp Listener Adapter service.

chris.house.00
  • 3,273
  • 1
  • 27
  • 36
  • checked. that is enabled as well. the Net.Tcp Listener Adapter service is set to auto start, and the NetTcpPortSharing Service is also set to auto start. – Apurv Aug 11 '11 at 00:48
  • Note, auo start just means it will start ehen eindows starts. If windows is already started it has no effect, then you need to start the service manually (or reboot) – Niels Brinch May 25 '13 at 08:41
0

In addition to the services that needed to be enabled I also had to enable IIS to recognize net.tcp. Right-click your website > Manage Application > Advanced Settings. The value for Enabled Protocols should be: http,net.tcp

Tresto
  • 151
  • 1
  • 12