我在控制台进程中托管了一个wcf服务 . 服务 endpoints 创建是通过代码在program.cs文件中使用net tcp绑定完成的 .

客户端创建通道是通过代码完成的 .

此设置在本地主机中正常工作 . 但是如果我在其他机器上托管该服务,并且如果我尝试从其他机器连接到服务(客户端IP地址更新),那么我得到以下错误 .

System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://10.10.1.1:8232/Service/. The connection attempt lasted for a time span of 00:00:00. TCP error code 10061: No connection could be made because the target machine actively refused it 10.10.1.1:8232. ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 10.10.1.1:8232

Note: 其他方案=>服务和客户端在同一台机器上运行 .

在服务主机中添加服务 endpoints 的URL地址为127.0.0.1 .

在客户端,如果我指定同一台机器的IP地址,则无法连接到该服务 .

但是如果我在服务 endpoints 配置中指定 localhost 而不是127.0.0.1,我就能够成功连接到服务 .

我不确定为什么它不适用于127.0.0.1,但可以在同一台机器上使用本地主机 . 这是预期的吗?

即使在本地主机更改后,我也无法连接到其他机器中的服务 .

欢迎任何建议 .

端口不会被防火墙阻止 .

通过代码的服务器端配置,

var tcpBinding = new NetTcpBinding(SecurityMode.None)
        {
            MaxBufferPoolSize = int.MaxValue,
            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
            ReaderQuotas =
            {
                MaxArrayLength = int.MaxValue,
                MaxNameTableCharCount = int.MaxValue,
                MaxStringContentLength = int.MaxValue,
                MaxDepth = int.MaxValue,
                MaxBytesPerRead = int.MaxValue
            },
            ReceiveTimeout = TimeSpan.MaxValue
        };

var host = new ServiceHost(typeof(Service));

host.AddServiceEndpoint(typeof(IService), tcpBinding, "net.tcp://localhost:8232/Service/");


        host.Open();

        Console.ReadLine();

        host.Close(); `

** Clinet侧配置**

string endPointAdress = "net.tcp://10.10.1.1:8232/Service";

var ServiceProxy = ChannelFactory.CreateChannel(tcpBinding,new EndpointAddress(endPointAdress));

  • / tcp绑定对于客户端和服务都是相同的 .

这个问题是否可能因数据 Contract 而发生?但如果它不适用于本地主机也是如此 . 如果我的理解是错误的,请更正 .

解决方案

从中更改服务器配置

** net.tcp://127.0.0.1:8232 / Service / net.tcp:// localhost:8232 / Service / **似乎解决了这个问题 . 并且所提到的解决方案可能对某些人有所帮助 . 可能有人可以帮忙为什么呢?谢谢大家 .