MSMQ to remote server

I am trying to path msmq messages to a specific terminal server if the user session is in terminal server 1(TS1)  then the message should queue to the local machine if the if in any other it should queue to TS1. My code is not quite correct I get a name error with this code. Can anyone help with the correct syntax?

If  Environment.MachineName = "TS1" Then
            toMyQueuePath = System.Configuration.ConfigurationManager.AppSettings("ToMyQueuePath")
            _toMyQueue = New MessageQueue(toMyQueuePath)
            _toMyQueue.Formatter = New XmlMessageFormatter(New Type() {GetType(XmlDocument)})
        Else
            toMyQueuePath = System.Configuration.ConfigurationManager.AppSettings("TS1\ToMyQueuePath")
            _toMyQueue = New MessageQueue(toMyQueuePath)
            _toMyQueue.Formatter = New XmlMessageFormatter(New Type() {GetType(XmlDocument)})
        End If
LVL 1
JoeBo747Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dennis AriesCEO @ Arkro ITCommented:
toMyQueuePath = System.Configuration.ConfigurationManager.AppSettings("TS1\ToMyQueuePath") ?
I think you are trying to:
toMyQueuePath = "TS1\\" + System.Configuration.ConfigurationManager.AppSettings("ToMyQueuePath")
 
The key you try to read from the appsettings does not exist.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JoeBo747Author Commented:
Hi djjaries:

I have given up on the method I was attempting and now have the following to write to the queue:

    Dim q As MessageQueue
                          q = New MessageQueue("FormatName:Direct=OS:ts1\Private$\JobsTransfer")
                    Dim m As New Messaging.Message()
            m.Body = document
            m.Label = "Jobs Test Message"
            q.Formatter = New XmlMessageFormatter(New Type() {GetType(XmlDocument)})
            q.Send(m)
                     q.Close()
The code throughs no errors but the message does not get written to the queue. Can you see why.
Regards
JoeBo
0
Dennis AriesCEO @ Arkro ITCommented:
Try to format the message instead of the queue. Formatting the queue is used for receiving the messages.

Dim q As MessageQueue
        q = New MessageQueue("FormatName:Direct=OS:ts1\Private$\JobsTransfer")
        Dim m As New Messaging.Message(document, New XmlMessageFormatter())
        m.Body = document
        m.Label = "Jobs Test Message"        
        q.Send(m)
        q.Close()

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.