无连接可以作出,因为目标机器积极地拒绝它127.0.0.1 [英] No connection could be made because the target machine actively refused it 127.0.0.1

查看:269
本文介绍了无连接可以作出,因为目标机器积极地拒绝它127.0.0.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试连接到主机使用WebRequest类在不同的服务器上的Web服务。 Web服务将返回一个字符串作为回应。这样做虽然我得到一个错误:




System.Net.Sockets.SocketException:无连接可以作出
,因为目标机器积极拒绝,



System.Net.WebException:无法连接到远程服务器--->
System.Net.Sockets.SocketException:无连接可以作出
,因为目标机器积极地在为$ b $
System.Net.Sockets.Socket.DoConnect(端点endPointSnapshot,
的SocketAddress的SocketAddress)拒绝了127.0.0.1:14012 b System.Net.ServicePoint.ConnectSocketInternal(布尔connectFailure,
插槽S4,S6插座,插座及放大器;插座,ip地址和放大器;地址,
ConnectSocketState状态,IAsyncResult的asyncResult,异常和放大器;
除外) - - 内部异常堆栈跟踪---在
System.Net.HttpWebRequest.GetRequestStream(TransportContext&安培;上下文)结束
在System.Net.HttpWebRequest.GetRequestStream()在
Limoallover.InsertSoapEnvelopeIntoWebRequestUS( XmlDocument的
soapEnvelopeXml,HttpWebRequest的WebRequest的)留在$ b $
Limoallover.dawUpdateDriverStatus(字符串apiId,字符串apiKey,字符串
idTrip,字符串tripCode,字符串的StatusCode)b Limoallover.UpdateJobStatus(字符串纬度,串液化天然气的Int32 DriverID,
的Int32 nJobStatus,的Int32 nJobId,字符串CompanyID,字符串idTrip,
串tripCode,字符串的StatusCode)




 私人HttpWebRequest的CreateWebRequestUS(URL字符串,字符串操作)
{
的HttpWebRequest的WebRequest =(HttpWebRequest的)WebRequest.Create(URL);
webRequest.Headers.Add(SOAPAction报,动作);
webRequest.ContentType =文本/ XML的,字符集= \UTF-8\;
webRequest.Accept =文/ XML;
webRequest.Method =POST;
回报率的WebRequest;
}

私人的XmlDocument CreateSoapEnvelopeUS(字符串apiId,串apiKey,串idTrip,串tripCode,字符串的StatusCode)
{
XmlDocument的soapEnvelop =新的XmlDocument();

串XML =<肥皂:信封的xmlns:XSI = \http://www.w3.org/2001/XMLSchema-instance\的xmlns:XSD = \HTTP ://www.w3.org/2001/XMLSchema\的xmlns:SOAP = \http://schemas.xmlsoap.org/soap/envelope/\>中;

XML = XML + @<肥皂:身体与GT;
XML = XML +< UpdateTripStatus的xmlns = \https://book.mylimobiz.com/api\>中;
XML = XML + @< apiId>中+ apiId +&下; / apiId>中;
XML = XML + @< apiKey>中+ apiKey +&下; / apiKey>中;
XML = XML + @< idTrip>中+ idTrip +&下; / idTrip>中;
XML = XML + @< tripCode>中+ tripCode +&下; / tripCode>中;
XML = XML + @<&的StatusCode GT; +的StatusCode +&下; /的StatusCode>中;
XML = XML + @< / UpdateTripStatus>中;
XML = XML + @< / SOAP:身体与GT;
XML = XML + @< / SOAP:信封>中;



soapEnvelop.LoadXml(XML);
返回soapEnvelop;
}用

私有静态无效InsertSoapEnvelopeIntoWebRequestUS(XmlDocument的soapEnvelopeXml,HttpWebRequest的WebRequest的)
{
(流流= webRequest.GetRequestStream())
$ { b $ b soapEnvelopeXml.Save(流);
}
}


解决方案

后6天我找到了答案这让我疯狂的答案是在Web配置文件


禁用代理

I try to connect to a web service hosted on a different server using the WebRequest Class. The web service returns a string as a Response. While doing so I get an Error:

"System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it"

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:14012 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at Limoallover.InsertSoapEnvelopeIntoWebRequestUS(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest) at Limoallover.dawUpdateDriverStatus(String apiId, String apiKey, String idTrip, String tripCode, String statusCode) at Limoallover.UpdateJobStatus(String Lat, String Lng, Int32 DriverID, Int32 nJobStatus, Int32 nJobId, String CompanyID, String idTrip, String tripCode, String statusCode)

private  HttpWebRequest CreateWebRequestUS(string url, string action)
{
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Headers.Add("SOAPAction", action);
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";
    return webRequest;
}

private  XmlDocument CreateSoapEnvelopeUS(string apiId, string apiKey, string idTrip, string tripCode, string statusCode)
{
    XmlDocument soapEnvelop = new XmlDocument();

    string xml = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";

    xml = xml + @"<soap:Body>";
    xml = xml + "<UpdateTripStatus xmlns=\"https://book.mylimobiz.com/api\">";
    xml = xml + @"<apiId>" + apiId + "</apiId>";
    xml = xml + @"<apiKey>" + apiKey + "</apiKey>";
    xml = xml + @"<idTrip>" + idTrip + "</idTrip>";
    xml = xml + @"<tripCode>" + tripCode + "</tripCode>";
    xml = xml + @"<statusCode>" + statusCode + "</statusCode>";
    xml = xml + @"</UpdateTripStatus>";
    xml = xml + @"</soap:Body>";
    xml = xml + @"</soap:Envelope>";



    soapEnvelop.LoadXml(xml);
    return soapEnvelop;
}

private static void InsertSoapEnvelopeIntoWebRequestUS(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
    using (Stream stream = webRequest.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }
}

解决方案

after six days i find the answer which make me crazy answer is disable proxy at web config file

这篇关于无连接可以作出,因为目标机器积极地拒绝它127.0.0.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆