2012-06-04 75 views
0

當我把下面的代碼的RESTful服務,我得到錯誤基礎連接已關閉:意外出錯一個接收

基礎連接已關閉: 發生意外的錯誤一個接收。

代碼:

Const url As String = "http://localhost:8003/Tracker/Tracker.svc/GetTrackerDetails" 

     ServicePointManager.MaxServicePointIdleTime = 500 
     ServicePointManager.UseNagleAlgorithm = True 
     ServicePointManager.Expect100Continue = True 
     ServicePointManager.CheckCertificateRevocationList = True 
     ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit 

     req = DirectCast(WebRequest.Create(url), HttpWebRequest) 
     req.Method = "POST" 
     req.ContentType = "application/xml; charset=utf-8" 
     req.Timeout = 300000 
     req.KeepAlive = False 
     req.Headers.Add("SOAPAction", url) 


     Dim xmlDoc = New XmlDocument With {.XmlResolver = Nothing} 

     xmlDoc.Load(Server.MapPath("Request.xml")) 
     Dim sXml As String = xmlDoc.InnerXml 
     req.ContentLength = sXml.Length 
     Dim sw = New StreamWriter(req.GetRequestStream()) 
     sw.Write(sXml) 
     sw.Close() 

     res = DirectCast(req.GetResponse(), HttpWebResponse) 
     Dim responseStream As Stream = res.GetResponseStream() 
     Dim streamReader = New StreamReader(responseStream) 

     'Read the response into an xml document 
     Dim soapResonseXmlDocument = New XmlDocument() 
     soapResonseXmlDocument.LoadXml(streamReader.ReadToEnd()) 


     TextBox1.Text = Server.HtmlDecode(soapResonseXmlDocument.InnerXml) 
     soapResonseXmlDocument.LoadXml(TextBox1.Text) 

我面對這個錯誤在過去的幾天。我的調用代碼有什麼問題。請幫助我。

+1

兩個說明:1)如果您通過瀏覽器調用服務,服務是否工作? 2)我看到你執行一個POST請求,如果回答我的第一個問題是'是'切換到GET – Alex

+0

當我通過瀏覽器調用服務時,我得到「方法不允許」,我只需要使用POST方法。我按要求傳遞XML。 POST是不可能的?我通過客戶端代碼調用它。但不是瀏覽器 –

+0

以前它是與郵政合作。我已經通過向其添加子節點和子子節點來更改請求xml。從那時起,我得到這個錯誤 –

回答

1

你應該在連接上安裝一些日誌記錄,在這種情況下,我猜想客戶端或服務器的請求或響應是很大的。

+0

什麼是日誌記錄可用於休息的工具以及我們需要在哪裏安裝客戶端或服務器? –

+0

我在服務跟蹤查看器日誌中只收到單個消息,即AppDomain卸載 –

0

問題可能發生在服務發生時,它無法解析您的請求XML或在處理請求時收到未知的異常錯誤。

相關問題