No connection could be made because the target machine actively refused it?

后端 未结 28 2046
北荒
北荒 2020-11-22 01:27

Sometimes I get the following error while I was doing HttpWebRequest to a WebService. I copied my code below too.


System.Net.WebException: Unable to connect         


        
相关标签:
28条回答
  • 2020-11-22 02:00

    For me, I wanted to start the mongo in shell (irrelevant of the exact context of the question, but having the same error message before even starting the mongo in shell)

    The process 'MongoDB Service' wasn't running in Services

    Start cmd as Administrator and type,

    net start MongoDB
    

    Just to see MongoDB is up and running just type mongo, in cmd it will give Mongo version details and Mongo Connection URL

    0 讨论(0)
  • 2020-11-22 02:02

    I had the same problem. The problem is that I didn't start the selenium server. I have downloaded the selenium server and i started it. After starting the selenium server, issue gone and all worked fine.

    Refer this : http://coding-issues.blogspot.in/2012/11/no-connection-could-be-made-because.html

    0 讨论(0)
  • 2020-11-22 02:03

    If this happens always, it literally means that the machine exists but that it has no services listening on the specified port, or there is a firewall stopping you.

    If it happens occasionally - you used the word "sometimes" - and retrying succeeds, it is likely because the server has a full 'backlog'.

    When you are waiting to be accepted on a listening socket, you are placed in a backlog. This backlog is finite and quite short - values of 1, 2 or 3 are not unusual - and so the OS might be unable to queue your request for the 'accept' to consume.

    The backlog is a parameter on the listen function - all languages and platforms have basically the same API in this regard, even the C# one. This parameter is often configurable if you control the server, and is likely read from some settings file or the registry. Investigate how to configure your server.

    If you wrote the server, you might have heavy processing in the accept of your socket, and this can be better moved to a separate worker-thread so your accept is always ready to receive connections. There are various architecture choices you can explore that mitigate queuing up clients and processing them sequentially.

    Regardless of whether you can increase the server backlog, you do need retry logic in your client code to cope with this issue - as even with a long backlog the server might be receiving lots of other requests on that port at that time.

    There is a rare possibility where a NAT router would give this error should its ports for mappings be exhausted. I think we can discard this possibility as too much of a long shot though, since the router has 64K simultaneous connections to the same destination address/port before exhaustion.

    0 讨论(0)
  • 2020-11-22 02:03

    When you call service which has only HTTP (ex: http://example.com) and you call HTTPS (ex: https://example.com), you get exactly this error - "No connection could be made because the target machine actively refused it"

    0 讨论(0)
提交回复
热议问题