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)

在过去的几天里,我面临着这个错误。我的调用代码有什么问题。请帮帮我。

4

2 回答 2

1

您应该在连接上安装一些日志记录,在这种情况下,我猜请求或响应对于客户端或服务器来说太大了。

于 2012-06-04T07:52:38.487 回答
0

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

于 2013-04-24T03:54:56.453 回答