开发者

Is the IP from the source or target in this System.Net.Sockets.SocketException?

开发者 https://www.devze.com 2022-12-23 16:36 出处:网络
I\'m making an outbound connection using a DNS name to a server other than the localhost, and I get this exception:

I'm making an outbound connection using a DNS name to a server other than the localhost, and I get this exception:

System.Net.WebEx开发者_运维百科ception: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:5555

The text implies that the TARGET machine refused the connection, but the IP address and port are from the localhost, which is kind of confusing. So is that IP address really the outgoing IP and port, even though the exception was caused by the target refusing the connection? Or is the exception from the local firewall blocking the outgoing connection?


The target machine actively refused it means that the port you are trying to connect to is definitely closed. In this case 5555. Try doing a netstat -an to check if the port is open, i.e. some service is listening on the port.

And if you are getting the local ip then most probably you have a dns resolution error and since you mention about the firewall that IS a possibility.


I am having the same issue and I can say that it is ONLY happening on web sites being ran on my local IIS.

I can make the requests through console apps, and other people are running the same code fine on their IIS instances. I may try to reinstall IIS to see if this fixes the problem if I can't find a solution online.

UPDATE:

Reinstalling IIS did not fix anything.

UPDATE 2:

I found that for some reason on my machine, the Proxy property of the HttpWebRequest object was being populated automatically, whereas on other machines it wasn't. Some config file somewhere must have got set to do this when I installed something. Explicitly setting request.Proxy = null was enough to get around this issue for me.

Hope this helps someone!

0

精彩评论

暂无评论...
验证码 换一张
取 消