I was trying to Unit Test my WCF Service, and for some crazy reason Visual Studio 2008 would issue a stop command to the IIS Admin service and the World Wide Web Publishing service, right before the unit test called the wcf service. As VS had cleverly stopped the services hosting my WCF service, the call subsequently failed with:
Test method [method] threw exception: System.ServiceModel.EndpointNotFoundException: Could not connect to http://localhost/WcfService/v1/MyService.svc. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:80. ---> System.Net.WebException: 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:80.
Found nothing to help me understand why VS behaved this way. I found that if the WCF project was unloaded the unit test would succeed. Interestingly enough a college was having another issue with WCF not using the proxy settings defined in the config. And found a good link about why here: http://blogs.infosupport.com/porint/archive/2007/08/14/Configuring-a-proxy_2D00_server-for-WCF.aspx
Originally I thought this may have been a similar cause, then my college found that turning off code coverage solved the problem. Open your localtestrun.testrunconfig and remove the code coverage checks. But now I'm not so sure as I still have the issue.