简体   繁体   English

WCF net tcp端口共享

[英]WCF net tcp port sharing

I have 2 WCF services each hosted in its own console app. 我有2个WCF服务,每个服务都在自己的控制台应用程序中托管

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. 启用net tcp端口共享服务。
  2. Registered the url`s using the commands: 使用命令注册url`s:

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 在每个WCF服务的绑定中启用PortSharingEnabled=true
  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: 如果我启动两个控制台应用程序,第二个总是在调用主机的Open()方法时给出此异常:

    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. 我的问题是:当每个服务托管在自己的控制台应用程序中时,如何使其工作。

As Jon_Lindeheim and you stated, this should work fine. 正如Jon_Lindeheim和你所说,这应该可行。 so i recreated everything from scratch as follows: 所以我从头开始重新创建如下:

I have two WCF services that had the same base address and a different relative URI 我有两个具有相同基址和不同相对URI的 WCF服务
ie for service 1: 即服务1:

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

and for service 2: 并为服务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. 我不知道基地址必须不同于最终的绝对URI。

so the following works fine: for service 1: 所以以下工作正常:服务1:

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

for service 2: 服务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 再次感谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM