R
Risen
Hi,All,
I read MSDN about MessageQueue,and then I want to write some code to test
MessageQueue in Vb.Net 2003. But there are some errors in code,and I don't
know which code are incorrect. Who can tell me how to correct it. Thanks a
lot.
Risen.
-------------------------------------------------------------------
Pls see my code as below:
Imports System
Imports System.Messaging
Public Class Form1
Inherits System.Windows.Forms.Form
......
......
Public Shared Sub EnsureQueueExists(ByVal path As String)
If Not MessageQueue.Exists(path) Then
MessageQueue.Create(path)
End If
End Sub 'EnsureQueueExists
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim queuePath As String = ".\private$\orders"
EnsureQueueExists(queuePath)
Dim queue As New MessageQueue(queuePath)
Dim orderRequest As New Order
orderRequest.itemId = 1025
orderRequest.quantity = 5
orderRequest.address = "One Microsoft Way"
queue.Send(orderRequest)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Console.WriteLine("Processing Orders")
Dim queuePath As String = ".\private$\orders"
EnsureQueueExists(queuePath)
Dim queue As New MessageQueue(queuePath)
CType(queue.Formatter, XmlMessageFormatter).TargetTypeNames = New
String() {"Order"}
While True
Dim newOrder As Order = CType(queue.Receive().Body, Order) '<-
Error!! But I don't know the reason that causes it.
newOrder.ShipItems()
End While
End Sub
End Class
Public Class Order
Public itemId As Integer
Public quantity As Integer
Public address As String
Public Sub ShipItems()
Console.WriteLine("Order Placed:")
Console.WriteLine(ControlChars.Tab & "Item ID : {0}", itemId)
Console.WriteLine(ControlChars.Tab & "Quantity : {0}", quantity)
Console.WriteLine(ControlChars.Tab & "Ship To : {0}", address)
' Add order to the database.
' Insert code here.
End Sub 'ShipItems
End Class 'Order
I read MSDN about MessageQueue,and then I want to write some code to test
MessageQueue in Vb.Net 2003. But there are some errors in code,and I don't
know which code are incorrect. Who can tell me how to correct it. Thanks a
lot.
Risen.
-------------------------------------------------------------------
Pls see my code as below:
Imports System
Imports System.Messaging
Public Class Form1
Inherits System.Windows.Forms.Form
......
......
Public Shared Sub EnsureQueueExists(ByVal path As String)
If Not MessageQueue.Exists(path) Then
MessageQueue.Create(path)
End If
End Sub 'EnsureQueueExists
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim queuePath As String = ".\private$\orders"
EnsureQueueExists(queuePath)
Dim queue As New MessageQueue(queuePath)
Dim orderRequest As New Order
orderRequest.itemId = 1025
orderRequest.quantity = 5
orderRequest.address = "One Microsoft Way"
queue.Send(orderRequest)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Console.WriteLine("Processing Orders")
Dim queuePath As String = ".\private$\orders"
EnsureQueueExists(queuePath)
Dim queue As New MessageQueue(queuePath)
CType(queue.Formatter, XmlMessageFormatter).TargetTypeNames = New
String() {"Order"}
While True
Dim newOrder As Order = CType(queue.Receive().Body, Order) '<-
Error!! But I don't know the reason that causes it.
newOrder.ShipItems()
End While
End Sub
End Class
Public Class Order
Public itemId As Integer
Public quantity As Integer
Public address As String
Public Sub ShipItems()
Console.WriteLine("Order Placed:")
Console.WriteLine(ControlChars.Tab & "Item ID : {0}", itemId)
Console.WriteLine(ControlChars.Tab & "Quantity : {0}", quantity)
Console.WriteLine(ControlChars.Tab & "Ship To : {0}", address)
' Add order to the database.
' Insert code here.
End Sub 'ShipItems
End Class 'Order