當我把下面的代碼的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)如果您通過瀏覽器調用服務,服務是否工作? 2)我看到你執行一個POST請求,如果回答我的第一個問題是'是'切換到GET – Alex
當我通過瀏覽器調用服務時,我得到「方法不允許」,我只需要使用POST方法。我按要求傳遞XML。 POST是不可能的?我通過客戶端代碼調用它。但不是瀏覽器 –
以前它是與郵政合作。我已經通過向其添加子節點和子子節點來更改請求xml。從那時起,我得到這個錯誤 –