2017-04-16 220 views
0

現在我嘗試從Windows服務調用本地服務器的Web服務,但我有錯誤 錯誤是「請求被中止:請求被取消。」 我的代碼是請求被中止:請求被取消

try { 
XmlDocument soapEnvelopeXml = new XmlDocument(); 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("xx.asmx"); 
request.UserAgent = "Mozilla/5.0"; 
request.Host = "server"; 
request.ContentType = "text/xml; charset=utf-8"; 
request.Headers.Add("SOAPAction", "\"xx\""); 
request.Method = "POST"; 
request.Accept = "text/xml"; 

soapEnvelopeXml.LoadXml(getXml(dt)); 
request.ContentLength = soapEnvelopeXml.OuterXml.Length; 
using (Stream Stream = request.GetRequestStream()) { 
    soapEnvelopeXml.Save(Stream); 
} 
using (WebResponse response = request.GetResponse()) { 

    using (StreamReader rd = new StreamReader(response.GetResponseStream())) { 
     string soapResalt = rd.ReadToEnd(); 
     CtlCommon.CreateErrorLog(strPath, soapResalt); 
    } 
} 


} catch (Exception ex) { 
    CtlCommon.CreateErrorLog(strPath, ex.InnerException.ToString); 
    CtlCommon.CreateErrorLog(strPath, ex.Message); 
} 

一段時間我試圖關閉流,StreamReader的和響應,但錯誤依然存在

+0

我是解決此評論的問題[CallWebService ](http://stackoverflow.com/a/4791932/4623058) –

回答

0

可以添加

request.Timeout = 2000 
    ServicePointManager.DefaultConnectionLimit = 1000 
    request.KeepAlive = False 
    request.ProtocolVersion = HttpVersion.Version10 
    request.ServicePoint.Expect100Continue = False 
+0

錯誤仍然存​​在 –

相關問題