Hi,All,
I read MSDN about MessageQueue,an d 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.Messagin g
Public Class Form1
Inherits System.Windows. Forms.Form
......
......
Public Shared Sub EnsureQueueExis ts(ByVal path As String)
If Not MessageQueue.Ex ists(path) Then
MessageQueue.Cr eate(path)
End If
End Sub 'EnsureQueueExi sts
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim queuePath As String = ".\private$\ord ers"
EnsureQueueExis ts(queuePath)
Dim queue As New MessageQueue(qu euePath)
Dim orderRequest As New Order
orderRequest.it emId = 1025
orderRequest.qu antity = 5
orderRequest.ad dress = "One Microsoft Way"
queue.Send(orde rRequest)
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Console.WriteLi ne("Processing Orders")
Dim queuePath As String = ".\private$\ord ers"
EnsureQueueExis ts(queuePath)
Dim queue As New MessageQueue(qu euePath)
CType(queue.For matter, XmlMessageForma tter).TargetTyp eNames = New
String() {"Order"}
While True
Dim newOrder As Order = CType(queue.Rec eive().Body, Order) '<-
Error!! But I don't know the reason that causes it.
newOrder.ShipIt ems()
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.WriteLi ne("Order Placed:")
Console.WriteLi ne(ControlChars .Tab & "Item ID : {0}", itemId)
Console.WriteLi ne(ControlChars .Tab & "Quantity : {0}", quantity)
Console.WriteLi ne(ControlChars .Tab & "Ship To : {0}", address)
' Add order to the database.
' Insert code here.
End Sub 'ShipItems
End Class 'Order