문제

We have some code that runs to connect to PayPal's PayFlowPro to update a credit card used within a recurring billing subscription. This code used to work fine under a .Net 2 app pool, but when we migrated it to 4.0 it's very touchy - sometimes it works and other times it doesn't. The code seems pretty straightforward so I'm not sure what the issue is.

The error is: System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Runtime.InteropServices.COMException (0x8000000A): The data necessary to complete this operation is not yet available.

The block of code that is intermittently failing (but used to work on an old server) is:

Try
objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
objWinHttp.Open("POST", GatewayHost, False)
objWinHttp.setRequestHeader("Content-Type", "text/namevalue") ' for XML, use text/xml
objWinHttp.SetRequestHeader("X-VPS-Timeout", "90")
objWinHttp.SetRequestHeader("X-VPS-Request-ID", requestID)

objWinHttp.Send(parmList)
 Catch exc As Exception

 End Try

 ' Get the text of the response. (DIES ON LINE BELOW)
 transaction_response = objWinHttp.ResponseText

The confusing part is it works intermittently which is always hardest to debug. This is something that has existed for years and the only difference is our app pool is now running under .Net 4 vs. .Net 2.0, but I wouldn't think that would be an issue. I flipped it back to 2.0 and now it's working flawlessly though.

Any guesses on where to start looking? Does WinHttp.WinHttpRequest.5.1 have issues in .Net 4? The old server was 2008 R2 and the new one is 2012 R1 so perhaps that's part of it as well?

Update - changing to 2.0 still didn't fix it. It was working and then stopped again. This doesn't make any sense.

도움이 되었습니까?

해결책

Since this was within inline .Net code (not compiled), I just migrated it to System.Net.HttpWebRequest instead which seems to be working much better. Here is sample code for anyone else hitting this:

Dim data As Byte() = New System.Text.ASCIIEncoding().GetBytes(parmList)
Dim request As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(GatewayHost), System.Net.HttpWebRequest)
request.Method = "POST"
request.ContentType = "text/namevalue"
request.ContentLength = data.Length

Dim requestStream As System.IO.Stream = request.GetRequestStream()
requestStream.Write(data, 0, data.Length)
requestStream.Close()

Dim responseStream = New System.IO.StreamReader(request.GetResponse().GetResponseStream())
transaction_response = responseStream.ReadToEnd()
responseStream.Close()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top