WebServiceexception – 基础连接已关闭:发送时发生意外错误

我编写了一个以下方法来从客户端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); } 

我已经吞下了下面的链接,但仍然没有结果。

An existing connection was forcibly closed by the remote host

上面的代码工作正常,如果我尝试从我的办公室网络和框。 此时我们正致力于网络拦截。