Windows Message Queue Service (VB.NET)
-
Heya, I'm trying To create a windows service that picks messages off of a MS message queue and send them to a GSM modem. I can post a message to the queue with a standard Windows app so there's no problem connecting to the queue. The problem is, I've made a service that finds the queue and begins receiving, it just never calls the ReceiveCompleted event, or if it does I never see it happen. I know it reads the queue once because if there is a message on the queue it disappears as soon as the service is started. If I add a message after that nothing happens. The code is as follows:
Private Sub HookQueue() Try ' Initialise our queue SMSMessageQueue = New MessageQueue(".\private$\SMSMessaging") SMSMessageQueue.Formatter = New System.Messaging.XmlMessageFormatter(New String() {"LAB.Messaging.SMS.SMSMessage"}) AddHandler SMSMessageQueue.ReceiveCompleted, AddressOf SMSMessageReceived SMSMessageQueue.BeginReceive() Catch exp As MessageQueueException EventLog.WriteEntry(exp.Message) Catch exp As Exception EventLog.WriteEntry(exp.Message) End Try End Sub
And the event code:Private Sub SMSMessageReceived(ByVal sender As Object, ByVal e As System.Messaging.ReceiveCompletedEventArgs) Handles SMSMessageQueue.ReceiveCompleted Try Dim SMSMessage As Message = sender.EndReceive(e.AsyncResult) 'SMSMessageQueue Dim oMessage As LAB.Messaging.SMS.SMSMessage = CType(SMSMessage.Body, LAB.Messaging.SMS.SMSMessage) 'TODO: Send message to GSM Modem here SMSMessageQueue.BeginReceive() Catch exp As MessageQueueException EventLog.WriteEntry(exp.Message) Catch exp As Exception EventLog.WriteEntry(exp.Message) End Try End Sub
I can't think of anything I'm doing wrong. Thanks :) Nicholas Rowan
The man who smiles when things go wrong has thought of someone he can blame it on. If you tell a man there are 300 billion stars in the universe, he'll believe you. But if you tell him a bench has just been painted, he'll have to touch it to be sure.