I have an application that is sending XML files up to a customer's site using the httpwebrequest and httpwegresponse objects. It has worked, hit and miss, but most recently I have run into a situation where assigning the httpwebrequest.getresponse to the httpwebresponse object seemingly just hangs and does nothing. An exception is not thrown and everything grinds to a hault. I have looked through a number of sites looking for info on this, but have not been able to find relevant articles. Any help would be much apreciated.
This is being written on a Windows Vista machine with Visual Studio 2005. I have tried this both behind and in front of our firewall with the same results. It might also be beneficial to have some way of tracing the request to see where it is hanging, but not sure how best to accomplish that.
This is being written on a Windows Vista machine with Visual Studio 2005. I have tried this both behind and in front of our firewall with the same results. It might also be beneficial to have some way of tracing the request to see where it is hanging, but not sure how best to accomplish that.
Code:
Public Function SendData2CustA(ByVal strURL As String, ByVal strFileName As String) As String
Dim webReq As HttpWebRequest
Dim i As Integer, mySTR As String
Dim mystore As New X509Store(StoreLocation.CurrentUser)
Dim certificate As X509Certificate2
If UserCert = "" Then
MsgBox("You must specify a SSL Certificate to use in the transmission. " & _
"Go to the options page and specify an appropriate certificate.", MsgBoxStyle.Exclamation, _
"Certificate Missing")
SendData2CustA = "ERROR,NO CERT,NO RESPONSE"
Exit Function
End If
Try
mystore.Open(OpenFlags.ReadOnly)
i = 0 : mySTR = ""
webReq = WebRequest.Create(strURL)
webReq.KeepAlive = False
webReq.Method = "POST"
webReq.AllowAutoRedirect = True
webReq.ContentType = "text/xml"
webReq.Timeout = 100000
webReq.AllowWriteStreamBuffering = True
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3
Dim instance As New WebProxy
Dim host As New Uri(strURL)
Dim returnValue As Boolean
returnValue = instance.IsBypassed(host)
For Each certificate In mystore.Certificates
If certificate.Subject.ToString = UserCert Then
Exit For
End If
i = i + 1
Next
certificate = mystore.Certificates(i)
webReq.ClientCertificates.Add(certificate)
Dim myRdr As StreamReader = New StreamReader(strFileName)
Dim myWrtr As StreamWriter = New StreamWriter(webReq.GetRequestStream)
myWrtr.Write(myRdr.ReadToEnd)
Dim myRsp As HttpWebResponse
If myRsp Is Nothing = False Then myRsp.Close()
myRsp = webReq.GetResponse()
Dim mySR As New StreamReader(myRsp.GetResponseStream)
SendData2CustA = myRsp.StatusCode & "," & _
myRsp.StatusDescription & "," & mySR.ReadToEnd
myWrtr.Close()
myRdr.Close()
Catch ex As Exception
SendData2CustA = "ERROR," & ex.Message & "," & ex.GetBaseException.ToString
End Try
End Function