【发布时间】:2014-07-15 20:05:40
【问题描述】:
我编写了以下方法来从客户端 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);
}
我已经关闭了下面的链接,但仍然没有结果。
【问题讨论】:
标签: c# .net web-services wcf iis