有时我得到以下错误,当我做HttpWebRequest到一个WebService。我也复制了下面的代码。


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
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetRequestStream()

ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.PreAuthenticate = true;
request.Credentials = networkCredential(sla);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = v_Timeout * 1000;

if (url.IndexOf("asmx") > 0 && parStartIndex > 0)
{
    AppHelper.Logger.Append("#############" + sla.ServiceName);

    using (StreamWriter reqWriter = new StreamWriter(request.GetRequestStream()))
    {                        
        while (true)
        {
            int index01 = parList.Length;
            int index02 = parList.IndexOf("=");

            if (parList.IndexOf("&") > 0)
                index01 = parList.IndexOf("&");

            string parName = parList.Substring(0, index02);
            string parValue = parList.Substring(index02 + 1, index01 - index02 - 1);

            reqWriter.Write("{0}={1}", HttpUtility.UrlEncode(parName), HttpUtility.UrlEncode(parValue));

             if (index01 == parList.Length)
                 break;

             reqWriter.Write("&");
             parList = parList.Substring(index01 + 1);
         }
     }
 }
 else
 {
     request.ContentLength = 0;
 }

 response = (HttpWebResponse)request.GetResponse();

当前回答

有一种服务叫做“SQL Server浏览器”,它向客户端提供SQL Server连接信息。

在我的例子中,现有的解决方案都不起作用,因为这个服务没有运行。我恢复了它,一切都恢复得很完美。

其他回答

好吧,我今天在64位的Windows 8上突然收到了这个错误,这是第一次,原来我的my.ini被重置了,bin/mysqld文件被删除了,以及“Program Files/MySQL/MySQL Server 5.6”文件夹中的其他项目。

为了解决这个问题,我不得不再次运行MySQL安装程序,只安装服务器,并从“ProgramData/MySQL/MySQL server 5.6”中复制my.ini文件的最新版本,在我的情况下命名为my_2014-03-28T15-51-20.ini(不知道为什么最近会复制到那里)回到“Program Files/MySQL/MySQL server 5.6”中。

自从MySQL工作以来,系统唯一的变化是安装了Native Instruments的Traktor 2和Traktor Audio 2声卡,这真的不应该引起这个问题,除了我之外没有其他人使用过这个系统。如果有人有线索,请评论以防止我和其他遇到这种情况的人。

I was facing this issue today. Mine was Asp.Net Core API and it uses Postgresql as the database. We have configured this database as a Docker container. So the first step I did was to check whether I am able to access the database or not. To do that I searched for PgAdmin in the start as I have configured the same. Clicking on the resulted application will redirect you to the http://127.0.0.1:23722/browser/. There you can try access your database on the left menu. For me I was getting an error as in the below image.

输入密码,并尝试是否能够访问它。对我来说,这行不通。因为它是一个Docker容器,我决定重新启动我的Docker桌面,右键单击任务栏中的Docker图标,然后单击重新启动。

在重新启动Docker后,我能够登录并看到数据库,并且当我在Visual Studio中重新启动应用程序时,错误也消失了。

希望能有所帮助。

我有同样的错误与我的WCF服务使用Net TCP绑定,但解决后启动以下服务在我的情况。

Net.Pipe.Listener.Adapter

Net.TCP.Listener.Adapter

网Tcp端口共享服务

在我的场景中,我有两个应用程序:

App1 App2

假设:App1应该监听App2在端口5000上的活动 错误:启动App1并试图监听一个不存在的鬼城,会产生错误 解决方案:首先启动App2,然后尝试使用App1监听

转到你的WCF项目- 属性- > -> 调试器 ->取消复选框的标记

启用“编辑并继续”