WCF Windows服务.可以在本地连接,但不能远程连接

nit*_*rog 7 c# wcf wcf-client

我花了两天时间试图解决这个问题而且我很难过.我有一个在Windows上作为服务运行的WCF服务器.客户端可以在同一台机器上连接到它,但是一旦我移动尝试连接到另一台机器上的服务我就不能.

因此,如果客户端和主机在同一台机器上,没有问题.如果主机和客户端位于不同的计算机上,则会出现异常错误.

这是奇怪的部分,我可以使用svcutil从远程机器生成app config和proxy.cs文件,但是一旦我调用该函数就会发出错误.

无法连接到net.tcp:// ipaddress:port/Service1.TCP错误代码10061.无法建立连接,因为目标计算机主动拒绝它.

如果我从同一台机器主机/客户端调用它没有错误.

有任何想法吗?

更新:

这是服务端点设置.

<system.serviceModel>
    <services>
        <service behaviorConfiguration="Service1Behavior" name="WcfServiceLibrary1.Service1">
            <endpoint address="net.tcp://192.168.1.75:8523/Service1" binding="netTcpBinding"
                contract="WcfServiceLibrary1.IService1" />
            <endpoint address="net.tcp://192.168.1.75:8523/mex" binding="mexTcpBinding"
                contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://192.168.1.75:8523/" />
                </baseAddresses>
            </host>
        </service>
    </services>
    <bindings>
        <netTcpBinding>
            <binding name = "TcpBindingConfiguration">
                <security mode="None"/>
            </binding>
        </netTcpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="Service1Behavior">
                <serviceMetadata />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

我尝试了一切.

有任何想法吗?

再次是客户端和主机在同一台机器上一切都很好,只要我把客户端放在另一台计算机上,没有骰子......

白天我从未对网络编程感到头疼...

谢谢

Jay*_*Jay 3

如果主机上启用了 Windows 防火墙,请尝试将其禁用(您可以通过控制面板到达那里)。如果它有效,那么你就找到了罪魁祸首。您需要在防火墙配置中为您的服务添加例外并重新启用它。

\n

如果您使用任何其他第三方防火墙软件(通常与防病毒软件捆绑在一起),情况也是如此。

\n

编辑:

\n

要设置 TCP 上的安全性,您可以在代码中使用构造函数:

\n
var binding = new NetTcpBinding(SecurityMode.None);\n
Run Code Online (Sandbox Code Playgroud)\n

或者您可以在配置 XML 中执行此操作:

\n
<netTcpBinding>\n    <binding name="myTcpBinding">\n        <security mode="None" />\n\xe2\x80\xa6\n
Run Code Online (Sandbox Code Playgroud)\n