M
Michael
Hi all..
I need to submit an asynchronous request for a credit card authorization. I
have an aspx page where the user confirms the transaction and clicks a
button to send the transaction to the authorization provider. When the
submit button is clicked, I hide the panel displaying the details and start
a client-side progress bar using a literal control. This has to be an async
call because if I start the request in the button click synchronously,
prerender doesn't get called until the request completes, so the progress
bar is never displayed. When the request completes, I need to redirect to a
page used to display the authorization code, etc.
I found an example of making an async request on MSDN and numerous other
similar examples on the web. However, none are web apps, which I found
curious. I was easy enough to incorporate the code into my web app - the
async request works fine and I get a proper response.
The problem is the redirect. It simply will not happen. Here is some
pertinent code.
Private Sub cmSubmit_Click()
lbStatus.Text = "Processing Transaction. Please Wait..."
pnConfirm.Visible = False
pnSubmit.Visible = True
startProcess.Text = "<script language='jscript'>startProcess();</script>"
'asp:literal
SendRequest()
End Sub
Private Sub SendRequest(ByVal PostData As String)
b = oEnc.ASCII.GetBytes(PostData)
oReq = CType(WebRequest.Create(URL), HttpWebRequest)
oReq.Method = "POST"
oReq.ContentType = "application/x-www-form-urlencoded"
oReq.ContentLength = PostData.Length
oState.Request = oReq
oStr = oReq.GetRequestStream()
oStr.Write(b, 0, b.Length)
Dim r As IAsyncResult = CType(oReq.BeginGetResponse(New
AsyncCallback(AddressOf RespCallback), oState), IAsyncResult)
End Sub
Public Sub RespCallback(ByVal ar As IAsyncResult)
oState = CType(ar.AsyncState, RequestState)
oReq = oState.Request
oRes = CType(oReq.EndGetResponse(ar), HttpWebResponse)
oStr = oRes.GetResponseStream
oState.ResponseStream = oStr
Dim iarRead As IAsyncResult = oStr.BeginRead(oState.ReadBuffer, 0,
oState.BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback), oState)
End Sub
Public Sub ReadCallback(ByVal asyncResult As IAsyncResult)
oState = CType(asyncResult.AsyncState, RequestState)
oStr = oState.ResponseStream
oRes = oState.Response
Dim read As Integer = oStr.EndRead(asyncResult)
If read > 0 Then
Dim c(oState.BUFFER_SIZE) As Char
Dim len As Integer = oState.StreamDecode.GetChars(oState.ReadBuffer, 0,
read, c, 0)
Dim str As String = New String(c, 0, len)
oState.RequestData.Append(str)
Dim ar As IAsyncResult = oStr.BeginRead(oState.ReadBuffer, 0,
oState.BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback), oState)
Else
oStr.Close()
oRes.Close()
If oState.RequestData.Length > 1 Then Response.Redirect("status.aspx")
'I've also tried server.transfer with the same results
End If
End Sub
I know this is possible; I see it every time I pay for anything online.
Thanks for any insight..
I need to submit an asynchronous request for a credit card authorization. I
have an aspx page where the user confirms the transaction and clicks a
button to send the transaction to the authorization provider. When the
submit button is clicked, I hide the panel displaying the details and start
a client-side progress bar using a literal control. This has to be an async
call because if I start the request in the button click synchronously,
prerender doesn't get called until the request completes, so the progress
bar is never displayed. When the request completes, I need to redirect to a
page used to display the authorization code, etc.
I found an example of making an async request on MSDN and numerous other
similar examples on the web. However, none are web apps, which I found
curious. I was easy enough to incorporate the code into my web app - the
async request works fine and I get a proper response.
The problem is the redirect. It simply will not happen. Here is some
pertinent code.
Private Sub cmSubmit_Click()
lbStatus.Text = "Processing Transaction. Please Wait..."
pnConfirm.Visible = False
pnSubmit.Visible = True
startProcess.Text = "<script language='jscript'>startProcess();</script>"
'asp:literal
SendRequest()
End Sub
Private Sub SendRequest(ByVal PostData As String)
b = oEnc.ASCII.GetBytes(PostData)
oReq = CType(WebRequest.Create(URL), HttpWebRequest)
oReq.Method = "POST"
oReq.ContentType = "application/x-www-form-urlencoded"
oReq.ContentLength = PostData.Length
oState.Request = oReq
oStr = oReq.GetRequestStream()
oStr.Write(b, 0, b.Length)
Dim r As IAsyncResult = CType(oReq.BeginGetResponse(New
AsyncCallback(AddressOf RespCallback), oState), IAsyncResult)
End Sub
Public Sub RespCallback(ByVal ar As IAsyncResult)
oState = CType(ar.AsyncState, RequestState)
oReq = oState.Request
oRes = CType(oReq.EndGetResponse(ar), HttpWebResponse)
oStr = oRes.GetResponseStream
oState.ResponseStream = oStr
Dim iarRead As IAsyncResult = oStr.BeginRead(oState.ReadBuffer, 0,
oState.BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback), oState)
End Sub
Public Sub ReadCallback(ByVal asyncResult As IAsyncResult)
oState = CType(asyncResult.AsyncState, RequestState)
oStr = oState.ResponseStream
oRes = oState.Response
Dim read As Integer = oStr.EndRead(asyncResult)
If read > 0 Then
Dim c(oState.BUFFER_SIZE) As Char
Dim len As Integer = oState.StreamDecode.GetChars(oState.ReadBuffer, 0,
read, c, 0)
Dim str As String = New String(c, 0, len)
oState.RequestData.Append(str)
Dim ar As IAsyncResult = oStr.BeginRead(oState.ReadBuffer, 0,
oState.BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback), oState)
Else
oStr.Close()
oRes.Close()
If oState.RequestData.Length > 1 Then Response.Redirect("status.aspx")
'I've also tried server.transfer with the same results
End If
End Sub
I know this is possible; I see it every time I pay for anything online.
Thanks for any insight..