Ok - been working for a long time on an app - working a backend service. When I debug this app it starts 4 services in the IDE and they all talk via http to each other. This has been working great for 12 months now.
Upon getting the latest release of MS updates - which included lots of changes to http.sys - this code below stopped working as expected. It works 4 out of 5 times - but sometimes blows up.
In the FINALLY - where I check to see if the response isnot nothing - I go to close the response and get an error of:
"An operation was attempted on a nonexistent network connection". What is the proper way to see if the response needs to be closed? I've attached an image of the RESPONSE object on a watch window.Code:Finally If response IsNot Nothing Then response.Close() End If End Try
And why is it all of a sudden behaving this way. The packets are all still flowing as expected - the program still runs as expected from what I see. It's just this clean-up code not awlays working the same way.
cl2.responseStart looks like thisCode:Dim response As HttpListenerResponse = Nothing Try If cl2.responseStart(request, FSOb, returnMessage) Then With FSOb Try Using dcn As New SqlConnection(m_ConnStr) Using cmd As New SqlCommand cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "Discovery_Load" ' "TagInfo_Load" cmd.Connection = dcn cmd.Parameters.AddWithValue("@GCId", .FileId) . . . cmd.Parameters.AddWithValue("@TagInfo", strTI) dcn.Open() Dim strMessage As String = cmd.ExecuteScalar.ToString End Using End Using Catch ex As Exception 'MessageBox.Show(ex.Message, "Archive Discovery_Load") End Try End With . . . rtnSize = cl2.responseEnd(response, context, FSOb, returnMessage) End If Catch ex As Exception returnMessage = ex.Message Finally If response IsNot Nothing Then response.Close() End If End Try
and cl2.responseEnd looks like thisCode:Public Function responseStart(ByRef request As HttpListenerRequest, ByRef FSOb As FSObject, ByRef TraceMsg As String) As Boolean Dim blnSuccess As Boolean = True TraceMsg = "" Try Dim inputstream As Stream = request.InputStream() Deserialize(FSOb, inputstream) 'FSOb.AffectCnt() TraceMsg = FSOb.DesiredAction If FSOb.FileId = 0 Then TraceMsg = "%Index " & FSOb.FileIndex.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Rcvd " & CInt((request.ContentLength64 + 1024) / 1024).ToString & " KB)" Else TraceMsg = "F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Rcvd " & CInt((request.ContentLength64 + 1024) / 1024).ToString & " KB)" & tagList(FSOb) End If 'If request.UserAgent = "search" Then If request.Headers("x-package") = "search" Then If FSOb.DesiredAction = "space" Then TraceMsg &= " search/space=" & FSOb.FNTagsCollection(0) ElseIf FSOb.DesiredAction = "enter" Then TraceMsg &= " search/enter=" & FSOb.FNTagsCollection(0) Else TraceMsg &= " search=" & FSOb.FNTagsCollection(0) End If End If 'If request.UserAgent = "searchdone" Then TraceMsg &= " narrowresult=" & FSOb.FNTagsCollection(0) Catch ex As HttpListenerException TraceMsg = ex.Message blnSuccess = False Catch ex As Exception TraceMsg = ex.Message blnSuccess = False End Try TraceMsg = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString.PadLeft(2, "0"c) & " S) " & TraceMsg Return blnSuccess End Function
Code:Public Function responseEnd(ByRef response As HttpListenerResponse, ByRef context As HttpListenerContext, ByRef FSOb As FSObject, ByRef TraceMsg As String) As Long Dim rtnSize As Long = 0 TraceMsg = "" Try 'FSOb.AffectCnt() response = context.Response Dim output As System.IO.Stream = response.OutputStream Using fsMS As New MemoryStream Serialize(FSOb, fsMS) output.Write(fsMS.ToArray, 0, CInt(fsMS.Length)) rtnSize = fsMS.Length If FSOb.ReaderRegistered Then TraceMsg = FSOb.SessionId.ToString & ">F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Send " & CInt((fsMS.Length + 1024) / 1024).ToString & " KB)" & tagList(FSOb) Else TraceMsg = FSOb.SessionId.ToString & ">F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Send " & CInt((fsMS.Length + 1024) / 1024).ToString & " KB)" End If End Using Catch ex As HttpListenerException TraceMsg = ex.Message Catch ex As Exception TraceMsg = ex.Message End Try TraceMsg = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString.PadLeft(2, "0"c) & " E) " & TraceMsg Return rtnSize End Function


Reply With Quote