473,763 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About MessageQueue Problem

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
Nov 21 '05 #1
4 1707

"Risen" <ri*****@21cn.c om> wrote in message
news:uw******** *****@tk2msftng p13.phx.gbl...
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.

<snip>
Can you quote the error messages you are getting and indicate to which lines
in your code they apply?
That would be very helpful to those interested in responding to your
question.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 21 '05 #2
Hi,Peter,

When app run at line "Dim newOrder As Order = CType(queue.Rec eive().Body,
Order)", the app has no response, and it does not show error messages. You
can test it in your own vs.net. I don't know what's wrong with it. Thanks a
lot.
Risen.

"Risen" <ri*****@21cn.c om> wrote in message
news:uw******** *****@tk2msftng p13.phx.gbl...
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.

<snip>
Can you quote the error messages you are getting and indicate to which
lines in your code they apply?
That would be very helpful to those interested in responding to your
question.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Nov 21 '05 #3

"Risen" <ri*****@21cn.c om> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi,Peter,

When app run at line "Dim newOrder As Order = CType(queue.Rec eive().Body,
Order)", the app has no response, and it does not show error messages. You
can test it in your own vs.net. I don't know what's wrong with it. Thanks
a lot.


The app does throw an error, but your test program is just badly designed.
You should catch and display the exception. Also it's easier to use a
Console Application as a test harness because it's completely
self-contained. I could just paste it into a new program and run it to
reproduce your error. There was nothing serious in your program, and with
better testing and debugging practices you would have gotten it working on
your own.

Anyway here's a proper test program with your problems fixed.

Imports System.Messagin g
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
Module Module1
Sub Main()
Try
Send()
Console.WriteLi ne("Send OK")

Recieve()
Console.WriteLi ne("Recieve OK")
Catch ex As Exception
Console.WriteLi ne(ex.ToString)

End Try

End Sub
Sub Send()

Dim queuePath As String = ".\private$\ord ers"
EnsureQueueExis ts(queuePath)
Dim queue As New MessageQueue(qu euePath)
queue.Formatter = New XmlMessageForma tter(New Type()
{GetType(Order) })
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
Sub Recieve()

Dim queuePath As String = ".\private$\ord ers"
Dim queue As New MessageQueue(qu euePath)
queue.Formatter = New XmlMessageForma tter(New Type()
{GetType(Order) })

For Each msg As Message In queue
Dim newOrder As Order = CType(msg.Body, Order)
newOrder.ShipIt ems()
Next

End Sub

Sub EnsureQueueExis ts(ByVal queuePath As String)
If Not System.Messagin g.MessageQueue. Exists(queuePat h) Then
MessageQueue.Cr eate(queuePath)
End If
End Sub

End Module
Nov 21 '05 #4
Thank you very much for your help. I will try according to what you said.
"David Browne" <davidbaxterbro wne no potted me**@hotmail.co m> дÈëÏûÏ¢ÐÂÎÅ:eb *************@T K2MSFTNGP10.phx .gbl...

"Risen" <ri*****@21cn.c om> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi,Peter,

When app run at line "Dim newOrder As Order = CType(queue.Rec eive().Body,
Order)", the app has no response, and it does not show error messages.
You can test it in your own vs.net. I don't know what's wrong with it.
Thanks a lot.


The app does throw an error, but your test program is just badly designed.
You should catch and display the exception. Also it's easier to use a
Console Application as a test harness because it's completely
self-contained. I could just paste it into a new program and run it to
reproduce your error. There was nothing serious in your program, and with
better testing and debugging practices you would have gotten it working on
your own.

Anyway here's a proper test program with your problems fixed.

Imports System.Messagin g
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
Module Module1
Sub Main()
Try
Send()
Console.WriteLi ne("Send OK")

Recieve()
Console.WriteLi ne("Recieve OK")
Catch ex As Exception
Console.WriteLi ne(ex.ToString)

End Try

End Sub
Sub Send()

Dim queuePath As String = ".\private$\ord ers"
EnsureQueueExis ts(queuePath)
Dim queue As New MessageQueue(qu euePath)
queue.Formatter = New XmlMessageForma tter(New Type()
{GetType(Order) })
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
Sub Recieve()

Dim queuePath As String = ".\private$\ord ers"
Dim queue As New MessageQueue(qu euePath)
queue.Formatter = New XmlMessageForma tter(New Type()
{GetType(Order) })

For Each msg As Message In queue
Dim newOrder As Order = CType(msg.Body, Order)
newOrder.ShipIt ems()
Next

End Sub

Sub EnsureQueueExis ts(ByVal queuePath As String)
If Not System.Messagin g.MessageQueue. Exists(queuePat h) Then
MessageQueue.Cr eate(queuePath)
End If
End Sub

End Module

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
469
by: d_well | last post by:
Hi, I use a MessageQueue in c#. I send a message in the queue with the command Send, here there is no problem. Then we I want to receive the message with the command Receive I receive the error message "Additional information: Invalid value 49.17:02:47.2960000 for parameter timeout." What is the problem.
3
5099
by: Gerhard Swart | last post by:
Hi all. I'm writing a queue browser that reads queues from a specified machine and then display the data that's on the queue. I am using the MessageQueue Class in .Net(C#). I get the problem that I can't read the journal private queue on a remote machine. I don't know if this is possible though. I have tried all the possible options but can't seem to get it to work. The code that I tried is: MessageQueue _mq = new MessageQueue(...
1
3729
by: Tony Hamill | last post by:
Hi, I am trying to create a C# application ( eventually a windows Service ) which will pick up the event when a message enters MSMQ. When this happens I want to log isome message details.This seems fairly straightforward. I had assumed using delegates was the way to go and found the following on msdn (...
2
1443
by: Charles Shao | last post by:
question about MessageQueue Hi, friends: I try to send a message into MSMQ and then read it out. But I find the message is not be removed after being accessed. How can I read and remove it ? Thanks
5
5753
by: felecha | last post by:
I have a VB.Net application that runs as a Windows Service and monitors a MessageQueue on another machine. At times that machine will have to be rebooted, so I've been working on how to get my Service to re-establish the connection after the remote machine is back. I found that as soon as the remote machine goes down, the BeginReceive() method and the ReceiveCompleted() event handler start throwing an exception, for QueueNotAvailable,...
2
2171
by: felecha | last post by:
I'm stumped. I'm working on an application in VB.Net that uses System.Messaging.MessageQueue to listen for messages sent to a private queue on a remote machine. Both machines are in the same Workgroup in a small private LAN. The messaging is working fine, but since the remote machine is used as a control system and has to be rebooted when there is a configuration change, I have to handle the remote queue going down and coming back up...
5
5013
by: Jason Richmeier | last post by:
I have been unable to locate an answer for this question because (1) it is late in the day and my eyes are tired of looking at code and documentation, (2) I am new to this area of the .NET framework, or (3) a combination of (1) and (2). I am looking at using messaging in an application I am working on. I have been reading the documentation about messaging and have been able to understand just about everything that I have read so far. I...
0
1470
by: chi.chung.ko | last post by:
Dear Pals local:Windows XP Sp2 server:Windows 2K3 Sever R2 When Use to Receive MessageQueue On Server System.Messaging.MessageQueue IQ = new MessageQueue(); IQ.Path = "FormatName:DIRECT=TCP:192.168.1.203\\public" return_msg = IQ.Receive();
1
1813
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
Is there any way to create an event that notifies when a message is added to a MessageQueue, without resorting to polling the MessageQueue? I.e., suppose we have a MessageQueue with several messages still in queue. My process wants to know when a new message (of any sort) is added to the queue. Right now I have a Timer invoking a refresh via GetAllMessages() to detect new messages. There must be a better way!
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.