【问题标题】:WebService Exception- The underlying connection was closed: An unexpected error occurred on a sendWebService Exception - 底层连接已关闭:发送时发生意外错误
【发布时间】: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);
}    

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

http://briancaos.wordpress.com/2012/06/15/an-existing-connection-was-forcibly-closed-by-the-remote-host/

【问题讨论】:

    标签: c# .net web-services wcf iis


    【解决方案1】:

    上面的代码工作正常,如果我从我的办公室网络和盒子尝试。目前我们正在努力阻止网络。

    【讨论】:

    • 不过,此问题已解决。正如我所怀疑的,我们在网络上被防火墙阻止了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2015-11-22
    • 2015-07-05
    相关资源
    最近更新 更多