【问题标题】:Listening on same port, different IP address, WCF + non-WCF app [closed]侦听相同的端口,不同的 IP 地址,WCF + 非 WCF 应用程序 [关闭]
【发布时间】:2012-10-26 10:20:50
【问题描述】:

我在具有 5 个虚拟 IP 地址 (IP1-IP5) 的机器的端口 IP1:80 上有一个应用程序绑定

然后我尝试将一个自托管的 WCF 服务绑定到 IP5:80,但得到一个 AlreadyInUseException。我猜 WCF 正在尝试绑定到整个 IP 范围,尽管我指定了一个特定的范围。

这是已知的行为吗?

            [start application that binds to IP1:80]


            string baseAddress = "http://IP5:80/binary";

            ServiceHost host = new ServiceHost(typeof(BinaryService),
                                               new Uri(baseAddress));


            host.AddServiceEndpoint(typeof(IBinaryService), GetBinding(), "")
                                   .Behaviors.Add(new WebHttpBehavior());

            host.Open(); // exception

【问题讨论】:

  • 是什么让你“猜测 WCF 试图绑定整个 IP 范围”?该IP上的端口不能只是在使用中,类似于this situation吗?
  • 我认为的原因是:我可以在 IP5:80 上运行非 wcf 应用程序的另一个实例,它工作得很好。另一方面,WCF 只会在所有 IP 上的端口都可用时才会启动。
  • “IP5”是计算机的名称吗?如果您这样做,WCF 将绑定到计算机,而不是特定的 IP 地址...
  • 不,这是一个 IP 地址。请参阅下面的解决方案。

标签: .net wcf networking tcp


【解决方案1】:

找到解决方案:

Run netsh
Type http
Type add iplisten ipaddress=IP5:80

在此之后,自托管的 WCF 应用将不会尝试绑定到 80 上的全范围,只是 IP5!

【讨论】:

    猜你喜欢
    • 2011-01-05
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    相关资源
    最近更新 更多