Я использую 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.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;
}
}
Код: Выделить всё
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. Блокируется ли он «выходом» или «входом» через маршрутизатор, до сих пор остается загадкой, но когда я запускаю клиент на другом компьютере физически за пределами моей локальной сети, он работает нормально
Подробнее здесь: https://stackoverflow.com/questions/835 ... cf-service