7

I have 2 WCF services each hosted in its own console app.

they are hosted at:

net.tcp://computername:7777/Service1
net.tcp://computername:7777/Service2

each has its own contract. i want them to use the same port, so i read a lot on the subject, and did the following:

  1. Enabled the net tcp port sharing service.
  2. Registered the url`s using the commands:

netsh http add urlacl user=domain\username url=net.tcp://+:7777/Service1

netsh http add urlacl user=domain\username url=net.tcp://+:7777/Service2

  1. enabled the PortSharingEnabled=true on the bindings in for each WCF service
  2. hosted each one in it`s own console app.

if i start both console apps, the second one always gives this exception on the call to the host's Open() method:

    AddressAlreadyInUseException. The transport manager failed to listen on the supplied 
    URI using the NetTcpPortSharing service: the URI is already registered with the 
    service.

when i host them both in the same console app, it all works just fine.

my question is: how to get it working when each service is hosted in it's own console app.

Menahem
  • 3,974
  • 1
  • 28
  • 43
  • I got this to work replicating all of your steps except "Registered the url's using the commands:" in Windows 7, .NET 4.5. – Jon Lindeheim May 14 '14 at 11:54
  • it seems you did everything necessary for port sharing. just double-check the following: 1 you created binding with portsharingEnabled = true, did you set the bindingConfiguration value in tag endPoint (in configuration file)? 2 try your program with another port number just in case settings in your previous test program did something prevent port-sharing happening. 3 from what i know, the netsh command is not required for port-sharing. – Yang You May 14 '14 at 11:58
  • @Jon_Lindeheim thanks, at least i know its supposed to work. all i need to do is recreate everything from scratch, and hope the mistake i did make will sorface. i`ll try to post back ASAP – Menahem May 14 '14 at 12:10
  • @yyou thanks for taking the time to help – Menahem May 14 '14 at 12:11

1 Answers1

3

As Jon_Lindeheim and you stated, this should work fine. so i recreated everything from scratch as follows:

I have two WCF services that had the same base address and a different relative URI
i.e. for service 1:

    <add baseAddress = "net.tcp://computername:7777/" />
    ...
    <endpoint address = "/service1" ... />

and for service 2:

    <add baseAddress = "net.tcp://computername:7777/" />
    ...
    <endpoint address = "/service2" ... />  

I was not aware that base addresses must be different not just the eventual absolute URI.

so the following works fine: for service 1:

    <add baseAddress = "net.tcp://computername:7777/service1/" />
    ...
    <endpoint address = "/service1" ... />

for service 2:

    <add baseAddress = "net.tcp://computername:7777/service2/" />
    ...
    <endpoint address = "/service2" ... />  

(why the first erroneous way still works when all is in one process, i think it's related to the way port sharing routes the traffic on a process based way).

Thanks again

bijayk
  • 556
  • 3
  • 18
Menahem
  • 3,974
  • 1
  • 28
  • 43