尝试连接到远程WCF服务时发生TCP错误(10060)

尝试连接到远程WCF服务时发生TCP错误(10060)

问题描述:

我有一个简单的WCF服务。由于各种原因,所有配置都是以编程方式完成的,而不是xml。服务是自己托管的。当我在本地机器上运行主机和客户端时,它运行良好。当我将主机移动到局域网中的另一台机器时,它也很好用。但是,当我尝试通过走出局域网(即使用我的路由器的WAN地址而不是本地局域网地址)到达任何一台机器上的主机时,它不起作用,并且出现下面的错误。 I am将路由器上的端口8100转发到服务主机。我还清除了主机防火墙上的端口,并尝试彻底关闭防火墙。两者都没有喜乐。尝试连接到远程WCF服务时发生TCP错误(10060)

我现在使用的TCP没有安全性,以保持简单。任何人都可以提出什么可能会导致这种行为?谢谢。

(注:我掩盖在下面的代码中的WAN和LAN地址。)

我的客户端类:

public class TrackingClient : IService 
{ 
    protected readonly Binding binding; 
    protected readonly EndpointAddress endpointAddress; 
    IService proxy; 

    public TrackingClient() 
    { 
     this.binding = new TCPBinding(); 
     this.endpointAddress = new EndpointAddress("net.tcp://WAN_IP:8100/Tracking"); 

     proxy = ChannelFactory<IService>.CreateChannel(
      binding, 
      endpointAddress); 
    } 

    public bool report(Payload payload) 
    { 
     return proxy.report(payload); 
    } 
} 

我的主机类:

 ServiceHost host = new ServiceHost(typeof(Service)); 
     host.AddServiceEndpoint(
      typeof(IService), 
      new TrackingComm.TCPBinding(), 
      "net.tcp://LAN_IP:8100/Tracking"); 

     host.Open(); 
     Console.WriteLine("=== TRACKING HOST ==="); 
     Console.ReadLine(); 
     host.Close(); 

我的绑定:

public class TCPBinding : NetTcpBinding 
{ 
    public TCPBinding() 
    { 
     Security.Mode = SecurityMode.None; 
     Security.Transport.ClientCredentialType = TcpClientCredentialType.None; 
     Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None; 
     Security.Message.ClientCredentialType = MessageCredentialType.None; 
    } 
} 

错误R I得到当客户端试图连接:

Could not connect to net.tcp://WAN_IP:8100/. The connection attempt lasted for a time span of 00:00:21.0772055. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond WAN_IP:8100. 

[编辑]

与此挣扎几天后,我终于设法追查问题我的路由器回环问题。虽然我仍然没有弄清楚为什么,但是发生的是,尽管路由器被设置为转发端口,但是当我使用WAN地址时,来自客户端的呼叫并未将其传送到主机。无论是通过路由器“走出去”还是“进入”,仍然是个谜,但是当我在局域网外的另一台计算机上运行客户端时,它运行得很好

要添加到的代理设置配置文件是如下:

<system.net> 
<defaultProxy> 
<proxy 
usesystemdefault = "false" 
proxyaddress="http://address:port" 
bypassonlocal="false" 
/> 
</defaultProxy> 
</system.net> 

[此外]
WCF service connection issue - maybe security?
[/添加]

+0

你可以使用TCP通道的代理吗?如果我明白[这](http://*.com/questions/520692/does-wcfs-nettcpbinding-supports-socks-proxy)的权利,你不能。 – Gadzooks34

+0

当然 - 你认为http使用什么类型的频道:) – KevinDTimm

+0

够公平的。然后我不得不承认我被卡住了。你知道我怎么可以包含你提供的信息,没有配置文件?我可以在BasicHttpBinding类中找到proxyAddress属性,但在NetTcpBinding类中找不到任何相关的东西。或者我可以以某种方式设置系统级别的默认属性? (这是从上面的配置代码片段看起来的样子)。 – Gadzooks34

这工作对我的服务:

<system.net> 
    <defaultProxy> 
     <proxy autoDetect="True"/> 
    </defaultProxy> 
</system.net>