-1

I'm newbie in WCF, so I really need your help.

I have two programs which uses WCF. If they are running on one computer and client uses adress net.tcp:\Localhost:8001\MyService to connect to server(which has adress 192.168.1.1 for example) everything is OK. But when I'm changing adress for client to net.tcp:\192.168.1.1:8001\MyService I'm getting system.timeoutexception because client cannot connect server.

Thanks for help.

Mario S
  • 11,715
  • 24
  • 39
  • 47
Alekstim
  • 452
  • 1
  • 8
  • 19
  • Are you running on the ASP.NET development server, or on a local IIS instance? – Matthew Kennedy Oct 25 '12 at 06:36
  • remember that localhost does not resolve to your specific IP address but to the 127.*.*.* range – il_guru Oct 25 '12 at 08:37
  • So what have you tried? _"Cannot connect to server"_ indicates a network-related error. Can you ping the address, telnet the port, is there a firewall or router in between, and so on. Basic network debugging. – CodeCaster Oct 25 '12 at 08:39
  • How are you hosting the Service? As you use net.tcp I assume you are hosting it in a .exe? – Fredrik Claesson Oct 25 '12 at 08:41

2 Answers2

1

You may need to allow external access to the port in the firewall.

As long as you're communication from localhost to localhost, the firewall doesn't come into play, as these requests are handled by the loopback adapter.

But when communicating from localhost to the machines IP address, you're making a network request that's handled by the firewall (even though you're still on the same machine physically).

By the way: For the server side it doesn't matter whether you start the WCF service with endpoint localhost or 192.168.1.1.

EDIT
I wrote that it doesn't matter whether you listen on localhost or 192.168.1.1 - this is only true if you only have one network adapter available.

As soon as there are two or more network cards (for example: Wireless LAN is turned on and you're connected via cable), localhost or 0.0.0.0 will make the service listen on any adapter. Using 192.168.1.1 will make the service listen only for connections on that IP address.

This is important to know especially in cases where the different network adapters become members of different (sub)networks.

For example: One adapter is connected to the 192.168.1 network and the other adapter is connected to the 192.168.2 network. If your service listens on localhost or 0.0.0.0 it will be reachable from both networks. If it only listens on 192.168.1.1, it will not be available for the 192.168.2 network.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
-2

Please check "192.168.1.1" is included in your "hosts" file. And give it a try.

The hosts file can be found in "C:\Windows\System32\drivers\etc"

Ant Radha
  • 2,233
  • 1
  • 13
  • 16
  • 1
    192.168.1.1 doesn't go into the hosts file, as the hosts file is meant to provide IP-address to name resolution. Theres no point (and it probably wouldn't work) to just add the IP address to the hosts file. – Thorsten Dittmar Oct 25 '12 at 08:33
  • Assuming that the issue is in dev environment, the "192.168.1.1" might be not accessible. Therefore I suggested including the ip in the hosts file. This has worked for me in the past. – Ant Radha Oct 25 '12 at 08:42
  • Putting an IP address (along with the corresponding hostname) in the `hosts` file would *only* make sense if he tried to communicate via *hostname*, as the `hosts` file is used to resolve the IP address for a host name (similar to what DNS does). You can *always* communicate between machines via IP address without any resolution service, so putting an entry into the `hosts` file to enable communication to an IP address doesn't help - and doesn't make sense. And I doubt that this was a working solution for you in the past - I bet you had other network-related problems. – Thorsten Dittmar Oct 25 '12 at 09:01