7

I'm having a tough time with NetTcpBinding.

When I run my WCFservice,I get this:

System.InvalidOperationException: Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
   at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
   at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
   at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName)
   at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
   at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)

I'm getting this when I run the application by default using WCFSvcHost. There's no extra code.Just the default code of any new wcf service. All I wanted to do was change the binding to tcp.

How do I solve this problem?

Edit: Here's my WCF's App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding" transferMode="Streamed" portSharingEnabled="false">
          <reliableSession enabled="true" />
          <security mode="None">
            <transport clientCredentialType="None" protectionLevel="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
        name="WcfServiceLibrary1.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="Service" binding="netTcpBinding" bindingConfiguration="tcpBinding"
          name="testTcp" contract="WcfServiceLibrary1.IService1" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary1.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Josh
  • 13,530
  • 29
  • 114
  • 159

5 Answers5

18

I'm sure by now you've fixed the issue, but it really is nothing to do with baseAddresses which is what all the bullentin boards lead you to. I found the answer at http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c9f8d99d-89ee-4573-8528-a21b047bad11. Assuming you are using IIS 7.x: right click the virtual directory/application in IIS, select Manage application -> Advanced settings. In the 'Enabled Protocols' section add net.tcp, e.g.: http,net.tcp. This is necessary even if you added this protocol already at the site level.

Helder
  • 236
  • 2
  • 3
  • I see that you also have security mode set to None in your bindings, which is what I started using at first, however, for what I'm doing I need to know the authenticated caller. I normally get this from OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name (http://www.leastprivilege.com/HostingWCFServicesInASPNETTheSurvivalGuide.aspx). So instead I changed the bindings on *both* the client and server to Windows as per http://msdn.microsoft.com/en-us/library/ms733089.aspx (Transport Security with Windows Authentication). – Helder Apr 21 '10 at 19:26
  • how to do this in IIS6? Any ideas? – NLV Jun 25 '10 at 11:59
  • Thank you... I have been staring at this config file for about 2 hours now and I couldn't figure out what was going on... – SoftwareSavant Jul 21 '11 at 13:40
  • YES YES YES, a thousand times YES; I forgot to do this and was having a bad time trying to figure out what I had to change, since I was certain that I did not need to provide a base address. – Bruno Brant Jul 08 '13 at 17:16
7

In this section

<host>          
  <baseAddresses>            
    <add baseAddress="http://localhost:8731/.../" />   
  </baseAddresses>        
</host>

add a net.tcp:// base address.

<host>
  <baseAddresses>
    <add baseAddress="http://localhost:8732/" />
    <add baseAddress="net.tcp://localhost"/>
  </baseAddresses>
</host>
Flea
  • 11,176
  • 6
  • 72
  • 83
Brian
  • 117,631
  • 17
  • 236
  • 300
  • adding that doesn't work.It says port is in use kind of error. Could you complete that line for me please? Thanks – Josh Aug 19 '09 at 04:30
  • System.ServiceModel.AddressAlreadyInUseException: The TransportManager failed to listen on the supplied URI using the NetTcpPortSharing service: the service failed to listen. – Josh Aug 19 '09 at 04:35
  • Be sure to use a different port (e.g. if http is on 8731, then use e.g. 8732: net.tcp://localhost:8732/Yadda/Blah/ ) – Brian Aug 19 '09 at 04:50
  • I can't use multiple ports since I'm planning to use it on a deployed asp.net app. I'm trying net.tcp sharing ...but it also fails.I've asked that error on a seperate question here.. http://stackoverflow.com/questions/1297865/wcf-multiple-bindings – Josh Aug 19 '09 at 04:58
  • I see portSharingEnabled=false in your app.config. That said, offhand I don't know if you can share http and tcp like that (don't recall). – Brian Aug 19 '09 at 05:47
  • Please see my reply on your other thread for an answer to the port sharing issue: http://stackoverflow.com/questions/1297865/wcf-multiple-bindings – jrista Aug 19 '09 at 23:53
3

You can share ports, it's not too hard.

Make sure when selecting enabled protocols in IIS (right click on site -> Manage Web Site -> Advanced Settings) that you DO NOT USE SPACES. If you have "http, net.tcp" instead of "http,net.tcp" it will not work, and instead give you this exact error.

More information here: http://www.weeksofprogramming.com/post/Could-not-find-a-base-address-Check-for-spaces-in-IIS7.aspx

Kellen
  • 621
  • 1
  • 5
  • 15
2

Configure net.tcp binding in your IIS site and set enabled protocol as "http,net.tcp using advanced setting".It should work

Ranjith
  • 21
  • 1
1
  1. Verify the Net.Tcp Port Sharing Service is started on the machine
  2. Verify the configuration netTcpBinding portSharingEnabled attribute is true. (In WCF4 you don't need to provide a name on the binding element if you want this binding specification to be the default for net.tcp)
Sean M
  • 616
  • 6
  • 16