底层连接已关闭:接收时发生意外错误

时间:2012-06-04 07:06:12

标签: vb.net wcf rest

当我使用以下代码调用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)

过去几天我遇到了这个错误。我的调用代码有什么问题。请帮帮我。

2 个答案:

答案 0 :(得分:1)

您应该在连接上安装一些日志记录,在这种情况下,我猜测客户端或服务器的请求或响应很大。

答案 1 :(得分:0)

当服务在处理请求时无法解析您的请求XML或出现未知异常错误时,可能会出现此问题。