WebService异常——底层连接已关闭:发送时发生意外错误
本文关键字:意外 错误 异常 连接 WebService | 更新日期: 2023-09-27 18:13:16
我已经编写了下面的方法来从客户端web服务检索XML响应。在下面的代码中,我收到的错误为{"无法从传输连接读取数据:远程主机强制关闭了现有连接。"}
请帮助。
下面代码错误
WebResponse webResponse = req.GetResponse();
调用WebService的方法-
[WebMethod]
public XmlDocument GetData()
{
string sError = "";
string sApiSession;
DateTime dtRequested = DateTime.Now;
XmlDocument xmlDoc = new XmlDocument();
XDocument xDoc = new XDocument();
try
{
NetworkCredential creds = new NetworkCredential();
creds.UserName = System.Configuration.ConfigurationManager.AppSettings.Get("UserName");
creds.Password = System.Configuration.ConfigurationManager.AppSettings.Get("Password");
WebRequest req = WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings.Get("Services"));
req.Method = System.Configuration.ConfigurationManager.AppSettings.Get("Method");
req.ContentType = System.Configuration.ConfigurationManager.AppSettings.Get("ContentType ");
req.Credentials = creds;
//Retriev into webresponse
WebResponse webResponse = req.GetResponse();
//Read from WebResponse to datastream
Stream dataStream = webResponse.GetResponseStream();
//read the content of data stream
using (StreamReader reader = new StreamReader(dataStream))
{
xDoc = XDocument.Load(reader);
}
}
catch (Exception ex)
{
throw;
}
return xmlDoc = getXml(xDoc);
}
我已经点击了下面的链接,但仍然没有结果。
http://briancaos.wordpress.com/2012/06/15/an-existing-connection-was-forcibly-closed-by-the-remote-host/以上代码运行良好,如果我尝试从我们的办公室网络和盒子。目前我们正在研究网络阻塞。