【问题标题】:Firewall blocking wcf lan client防火墙阻止 wcf 局域网客户端
【发布时间】:2025-12-15 08:55:02
【问题描述】:

我在 WINDOWS 7 操作系统上托管了我的 WCF windows 服务,并在 windows-XP PC 上安装了客户端应用程序。 WIN-7 防火墙阻止了我的 XP 客户端应用程序,当我在 Win-7 上禁用防火墙时,客户端应用程序运行良好。我怎样才能克服这个问题。我正在为所有基于局域网的客户端应用程序使用 security mode="none"

客户端配置文件

<system.serviceModel>
    <bindings>
        <netNamedPipeBinding>
            <binding name="NetNamedPipeBinding_IDataService" >
                <security mode="Transport">
                    <transport protectionLevel="EncryptAndSign" />
                </security>
            </binding>
        </netNamedPipeBinding>
        <netTcpBinding>
            <binding name="NetTcpBinding_IDataService">
                <security mode="None">                        
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost:8523/DataServices" binding="netTcpBinding"
            bindingConfiguration="NetTcpBinding_IDataService" contract="DataServiceReference.IDataService"
            name="NetTcpBinding_IDataService" />
        <endpoint address="net.pipe://localhost/" binding="netNamedPipeBinding"
            bindingConfiguration="NetNamedPipeBinding_IDataService" contract="DataServiceReference.IDataService"
            name="NetNamedPipeBinding_IDataService">                
        </endpoint>
    </client>
</system.serviceModel>

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    或者,您可以在高级安全 Windows 防火墙的入站规则中添加/启用 Windows Communication Foundation Net.TCP 侦听器适配器 (TCP-In)

    【讨论】:

      【解决方案2】:

      您不需要禁用防火墙。您的配置在此处定义了 2 个端点。虽然 net.tcp 会被防火墙阻止,但 net.pipe 不会受到影响。因此,只需在您的客户端中使用 NetNamedPipeBinding_IDataService 端点。

      如果由于某种原因这不起作用或客户端不在同一个域中(net.pipe 的范围),您可以使用 wsHttpBinding 甚至更简单的 basicHttpBinding。这将使用端口 80 上的 Http,如果您的服务器安装了 IIS,这很可能是打开的。

      【讨论】:

        【解决方案3】:

        您通过禁用防火墙解决了这个问题。在 WCF 配置中没有什么可以绕过主机上的防火墙。如果您绑定的端口被阻塞,则不会有任何数据到达终点。

        【讨论】: