8

This really is bugging me for a couple of hours. I created the simplest WCF service using a TCP binding.

namespace WcfTcpService
{
    public class TestTcpService : ITestTcpService
    {
        public string Hello(string name)
        {
            return "Hello, " + name + "!";
        }
    }
}

namespace WcfTcpService
{
    [ServiceContract]
    public interface ITestTcpService
    {
        [OperationContract]
        string Hello(string name);
    }
}

Web.config file has the following section:

  <system.serviceModel>
    <services>
      <service name="WcfTcpService.TestTcpService" behaviorConfiguration="TestServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:808/WcfTcpService.TestTcpService" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding" contract="WcfTcpService.ITestTcpService"></endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding" portSharingEnabled="true">
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="TestServiceBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
      <add binding="netTcpBinding" scheme="net.tcp" />
    </protocolMapping>-->    
    <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />-->
  </system.serviceModel>

This service is hosted in IIS:

detailed settings

Now, when trying to add a reference to net.tcp://localhost:808/WcfTcpService.TestTcpService from a client application, I keep receiving the error:

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/WcfTcpService.TestTcpService'.
The message could not be dispatched because the service at the endpoint address 'net.tcp://localhost/WcfTcpService.TestTcpService' is unavailable for the protocol of the address.
If the service is defined in the current solution, try building the solution and adding the service reference again.

The net.tcp service is running, I receive the same error with WcfTestClient.exe. and I can succesfully run http://localhost/WcfTcpService/TestTcpService.svc.

I've searched google but nothing came up.

Thanks!

EDIT:

The bindings screen of the 'Default Web site' looks like this btw:

bindings

Nullius
  • 2,607
  • 2
  • 16
  • 22
  • 1
    Do you get this error when you choose "Add service reference"? Try address http://localhost/WcfTcpService/TestTcpService.svc in this dialog. – empi Jul 26 '13 at 16:05
  • Check the bindings in iis/iis express See this question: http://stackoverflow.com/questions/3188618/enabling-net-tcp – nakchak Jul 26 '13 at 16:06
  • @empi You have got to be kidding me ... that works. If you post this as a solution, I'll accept it. Thanks! – Nullius Jul 26 '13 at 16:24
  • @nakchak You probably were too late to see my edit right after I posted my question but the bindings were correct. Thanks anyway! – Nullius Jul 26 '13 at 16:26
  • @Nullius Added the answer so others would find the solution easily – empi Jul 26 '13 at 18:50

2 Answers2

9

When you create service that uses netTcpBinding and you want to Add service reference in Visual Studio you should use http address (httpGetEnabled) not actual tcp address the service listens on. So the solution was to set localhost/WcfTcpService/TestTcpService.svc as an url in Add service reference dialog.

empi
  • 15,755
  • 8
  • 62
  • 78
  • 1
    Just to be complete: it's actually `net.tcp://localhost/WcfTcpService/TestTcpService.svc` that did the trick. – Nullius Jul 26 '13 at 19:30
0

I had same problem and I changed web.config as below:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
      <baseAddressPrefixFilters>
        <add prefix="net.tcp://YourBaseUrl"/>
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
Zoe
  • 27,060
  • 21
  • 118
  • 148