0

我们有一些代码可以运行以连接到 PayPal 的 PayFlowPro,以更新在定期计费订阅中使用的信用卡。这段代码过去在 .Net 2 应用程序池下运行良好,但是当我们将其迁移到 4.0 时,它非常棘手 - 有时它可以工作,有时则不能。代码看起来很简单,所以我不确定问题是什么。

错误是: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.

间歇性失败的代码块(但用于在旧服务器上工作)是:

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

令人困惑的部分是它间歇性地工作,这总是最难调试。这是多年来一直存在的东西,唯一的区别是我们的应用程序池现在在 .Net 4 与 .Net 2.0 下运行,但我认为这不是问题。我将它翻回 2.0,但现在它可以完美运行。

关于从哪里开始寻找的任何猜测?WinHttp.WinHttpRequest.5.1 在 .Net 4 中有问题吗?旧服务器是 2008 R2,新服务器是 2012 R1,所以也许这也是其中的一部分?

更新- 更改为 2.0 仍然没有修复它。它正在工作,然后又停止了。这没有任何意义。

4

1 回答 1

0

由于这是内联 .Net 代码(未编译),我只是将它迁移到 System.Net.HttpWebRequest ,而不是它似乎工作得更好。以下是其他任何人的示例代码:

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()
于 2014-01-17T19:43:33.670 回答