2014-07-15 115 views
0

我已經編寫了以下方法來從客戶端Web服務檢索XML響應。 在下面的代碼,我收到了錯誤的{「無法讀取從傳輸連接數據:現有的連接被強行關閉遠程主機。」}WebService異常 - 底層連接已關閉:發送時出現意外錯誤

請幫助。

錯誤在下面的代碼

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/

回答

0

上面的代碼工作正常,如果我從我們我的辦公室網絡和箱的嘗試。此時我們正在研究網絡阻塞問題。

+0

但是,此問題已解決。正如我懷疑的那樣,我們在網絡上阻止了防火牆。 –

相關問題