Response.Write from VB.NET class?

C

Chizl

I'm an old VB/C++/ASP developer, but very new to .Net web development. I
have a thought, but I need help implementing it.. Also, because I can't get
past the first part, I'm not sure I can even do what I'm trying to do..

I know I can't response.write from the class, but I need to understand how I
can get the data back to my ASPX file from a callback method.

I created a ASP.NET Web Application..
I have an MSMQ Class (msmq.vb) with 3 methods in it..
1. Send Text to Queue
2. Listen Async to Queue
3. Call back method for Listen

---- Code is below...-----

Can someone explain to me how in my CallBack method, I can write data to the
client? Basically a response.write type functionality.
Also I found some of this code, so I need some explanation why they used:
mq.BeginReceive(), as the method is exiting.. Wouldn't the garbage
collector kill this var, sooner or later?

----------------------------------------
Imports Microsoft.VisualBasic
Imports System.Xml
Imports System.Messaging

Namespace PayDay
Public Class CMSMQ
Private m_sMQPath As String = ".\private$\TesterQ"

Public Sub SendMessagetoQueue(ByVal Text As String)
Try
If MessageQueue.Exists(m_sMQPath) = False Then
MessageQueue.Create(m_sMQPath)
End If

Dim mq As MessageQueue = New MessageQueue(m_sMQPath)
Dim formatter As XmlMessageFormatter = CType(mq.Formatter,
XmlMessageFormatter)
formatter.TargetTypeNames = New String()
{"System.String,mscorlib"}

mq.Send(Text)
Catch ex As Exception
Throw ex
End Try
End Sub

Public Sub MQListen()
If (Not MessageQueue.Exists(m_sMQPath)) Then
MessageQueue.Create(m_sMQPath)
End If

Dim mq As MessageQueue = New MessageQueue(m_sMQPath)
Dim formatter As XmlMessageFormatter = CType(mq.Formatter,
XmlMessageFormatter)
formatter.TargetTypeNames = New String()
{"System.String,mscorlib"}

AddHandler mq.ReceiveCompleted, AddressOf OnReceiveCompleted
Try
mq.BeginReceive()
Catch ex As Exception
Throw ex
End Try
End Sub

Private Sub OnReceiveCompleted(ByVal source As Object, ByVal
asyncResult As ReceiveCompletedEventArgs)
Dim mq As MessageQueue = CType(source, MessageQueue)
Dim m As Message = mq.EndReceive(asyncResult.AsyncResult)

Dim body As String
body = m.Body.ToString

Dim xmlstring As String
xmlstring = m.Body.ToString
' Response.Write(xmlstring) 'Send Text to the Browser
????
mq.BeginReceive() 'Don't know what this is...
????
End Sub
End Class
End Namespace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top