Message queues

S

Simon Hart [MVP]

You can only post messages to a remote private queue. You can't peek them, or
call the BeginReceive, Receive and register the ReceiveCompleted event
handler.

Sounds like you need to define a public queue instead of a private one.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


David said:
Here is some code. The m_queue.BeginReceive method gets called, but
after a few seconds it throws an exception which is caught, but the ex
variable is null. My MessageArrived method is never called either even
though I have added it to the ReceiveCompleted event. Now I dont know what
to do. This is pretty darn simple code. I can see two messages in the queue
on david-1. I can run the server app on david-1 at the same time as the
remote side is running. The server app creates new entries but still the
MessageArrived handler is not called and a bogus exception is thrown.

Ideas why this does not work?

public partial class Form1 : Form
{
private MessageQueue m_queue;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
string deviceIP = String.Empty;
IPAddress[] addresses =
Dns.GetHostEntry("david-1").AddressList;
for (int i = 0; i < addresses.Length; ++i)
{
IPAddress addr = addresses;
if (addr.AddressFamily == AddressFamily.InterNetwork)
{
deviceIP = addr.ToString();
break;
}
}
if (deviceIP == String.Empty)
{
MessageBox.Show("Unable to retrieve Device IP");
Close();
return;
}

String strPath =
String.Format(@"FormatName:DIRECT=TCP:{0}\PRIVATE$\CallerID", deviceIP);
m_queue = new MessageQueue(strPath);

if (m_queue != null)
{
System.Type[] types = new Type[1];
types[0] = typeof(CallerIDClient.CallerID);
m_queue.Formatter = new XmlMessageFormatter(types);

try
{
m_queue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MessageArrived);
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
Close();
}

Thread t1 = new Thread(PeekMessages);
t1.IsBackground = true;
t1.Start();
}
else
{
MessageBox.Show("Queue not created");
Close();
}
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}

private void PeekMessages()
{
while (true)
{
try
{
m_queue.BeginReceive();
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}

public void MessageArrived(Object source, ReceiveCompletedEventArgs
args)
{
MessageQueue queue = source as MessageQueue;
Message message = queue.EndReceive(args.AsyncResult);

CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}

private void AddItem(String strID)
{
Message message = m_queue.PeekById(strID);
CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}
}
 
D

David

Does a public queue require a domain server to be in place, that is, a
server that has Active Directory?

Simon Hart said:
You can only post messages to a remote private queue. You can't peek them,
or
call the BeginReceive, Receive and register the ReceiveCompleted event
handler.

Sounds like you need to define a public queue instead of a private one.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


David said:
Here is some code. The m_queue.BeginReceive method gets called, but
after a few seconds it throws an exception which is caught, but the ex
variable is null. My MessageArrived method is never called either even
though I have added it to the ReceiveCompleted event. Now I dont know
what
to do. This is pretty darn simple code. I can see two messages in the
queue
on david-1. I can run the server app on david-1 at the same time as the
remote side is running. The server app creates new entries but still the
MessageArrived handler is not called and a bogus exception is thrown.

Ideas why this does not work?

public partial class Form1 : Form
{
private MessageQueue m_queue;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
string deviceIP = String.Empty;
IPAddress[] addresses =
Dns.GetHostEntry("david-1").AddressList;
for (int i = 0; i < addresses.Length; ++i)
{
IPAddress addr = addresses;
if (addr.AddressFamily == AddressFamily.InterNetwork)
{
deviceIP = addr.ToString();
break;
}
}
if (deviceIP == String.Empty)
{
MessageBox.Show("Unable to retrieve Device IP");
Close();
return;
}

String strPath =
String.Format(@"FormatName:DIRECT=TCP:{0}\PRIVATE$\CallerID", deviceIP);
m_queue = new MessageQueue(strPath);

if (m_queue != null)
{
System.Type[] types = new Type[1];
types[0] = typeof(CallerIDClient.CallerID);
m_queue.Formatter = new XmlMessageFormatter(types);

try
{
m_queue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MessageArrived);
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
Close();
}

Thread t1 = new Thread(PeekMessages);
t1.IsBackground = true;
t1.Start();
}
else
{
MessageBox.Show("Queue not created");
Close();
}
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}

private void PeekMessages()
{
while (true)
{
try
{
m_queue.BeginReceive();
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}

public void MessageArrived(Object source,
ReceiveCompletedEventArgs
args)
{
MessageQueue queue = source as MessageQueue;
Message message = queue.EndReceive(args.AsyncResult);

CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}

private void AddItem(String strID)
{
Message message = m_queue.PeekById(strID);
CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}
}



Simon Hart said:
Are you running the following line:
MessageQueue.Exists(@"david-1\private$\callerid") on a remote machine
(not
on
david-1)? if so this is not supported for private queues. Checking the
existence of remote queues can only be done if the queue is public - in
which
case active directory is required.

When executing the Exists method on a local machine the proper syntax
is:
MessageQueue.Exists(@".\private$\callerid").

Period '.' meaning localhost machine.
 
D

David

And the two computers communicating must be a member of that domain and not
a workgroup computer in order to send and receive messages?

David said:
Does a public queue require a domain server to be in place, that is, a
server that has Active Directory?

Simon Hart said:
You can only post messages to a remote private queue. You can't peek
them, or
call the BeginReceive, Receive and register the ReceiveCompleted event
handler.

Sounds like you need to define a public queue instead of a private one.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


David said:
Here is some code. The m_queue.BeginReceive method gets called, but
after a few seconds it throws an exception which is caught, but the ex
variable is null. My MessageArrived method is never called either even
though I have added it to the ReceiveCompleted event. Now I dont know
what
to do. This is pretty darn simple code. I can see two messages in the
queue
on david-1. I can run the server app on david-1 at the same time as the
remote side is running. The server app creates new entries but still the
MessageArrived handler is not called and a bogus exception is thrown.

Ideas why this does not work?

public partial class Form1 : Form
{
private MessageQueue m_queue;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
string deviceIP = String.Empty;
IPAddress[] addresses =
Dns.GetHostEntry("david-1").AddressList;
for (int i = 0; i < addresses.Length; ++i)
{
IPAddress addr = addresses;
if (addr.AddressFamily ==
AddressFamily.InterNetwork)
{
deviceIP = addr.ToString();
break;
}
}
if (deviceIP == String.Empty)
{
MessageBox.Show("Unable to retrieve Device IP");
Close();
return;
}

String strPath =
String.Format(@"FormatName:DIRECT=TCP:{0}\PRIVATE$\CallerID",
deviceIP);
m_queue = new MessageQueue(strPath);

if (m_queue != null)
{
System.Type[] types = new Type[1];
types[0] = typeof(CallerIDClient.CallerID);
m_queue.Formatter = new XmlMessageFormatter(types);

try
{
m_queue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MessageArrived);
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
Close();
}

Thread t1 = new Thread(PeekMessages);
t1.IsBackground = true;
t1.Start();
}
else
{
MessageBox.Show("Queue not created");
Close();
}
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}

private void PeekMessages()
{
while (true)
{
try
{
m_queue.BeginReceive();
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}

public void MessageArrived(Object source,
ReceiveCompletedEventArgs
args)
{
MessageQueue queue = source as MessageQueue;
Message message = queue.EndReceive(args.AsyncResult);

CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}

private void AddItem(String strID)
{
Message message = m_queue.PeekById(strID);
CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}
}



Are you running the following line:
MessageQueue.Exists(@"david-1\private$\callerid") on a remote machine
(not
on
david-1)? if so this is not supported for private queues. Checking the
existence of remote queues can only be done if the queue is public -
in
which
case active directory is required.

When executing the Exists method on a local machine the proper syntax
is:
MessageQueue.Exists(@".\private$\callerid").

Period '.' meaning localhost machine.


 
D

David

This link indicates that you can send and receive messages to private queues
if a direct connection is available. Am I reading this wrong?

http://technet2.microsoft.com/windo...813b-46a5-9397-d303ba5c18831033.mspx?mfr=true

David said:
And the two computers communicating must be a member of that domain and
not a workgroup computer in order to send and receive messages?

David said:
Does a public queue require a domain server to be in place, that is, a
server that has Active Directory?

Simon Hart said:
You can only post messages to a remote private queue. You can't peek
them, or
call the BeginReceive, Receive and register the ReceiveCompleted event
handler.

Sounds like you need to define a public queue instead of a private one.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Here is some code. The m_queue.BeginReceive method gets called, but
after a few seconds it throws an exception which is caught, but the ex
variable is null. My MessageArrived method is never called either even
though I have added it to the ReceiveCompleted event. Now I dont know
what
to do. This is pretty darn simple code. I can see two messages in the
queue
on david-1. I can run the server app on david-1 at the same time as the
remote side is running. The server app creates new entries but still
the
MessageArrived handler is not called and a bogus exception is thrown.

Ideas why this does not work?

public partial class Form1 : Form
{
private MessageQueue m_queue;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
string deviceIP = String.Empty;
IPAddress[] addresses =
Dns.GetHostEntry("david-1").AddressList;
for (int i = 0; i < addresses.Length; ++i)
{
IPAddress addr = addresses;
if (addr.AddressFamily ==
AddressFamily.InterNetwork)
{
deviceIP = addr.ToString();
break;
}
}
if (deviceIP == String.Empty)
{
MessageBox.Show("Unable to retrieve Device IP");
Close();
return;
}

String strPath =
String.Format(@"FormatName:DIRECT=TCP:{0}\PRIVATE$\CallerID",
deviceIP);
m_queue = new MessageQueue(strPath);

if (m_queue != null)
{
System.Type[] types = new Type[1];
types[0] = typeof(CallerIDClient.CallerID);
m_queue.Formatter = new XmlMessageFormatter(types);

try
{
m_queue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MessageArrived);
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
Close();
}

Thread t1 = new Thread(PeekMessages);
t1.IsBackground = true;
t1.Start();
}
else
{
MessageBox.Show("Queue not created");
Close();
}
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}

private void PeekMessages()
{
while (true)
{
try
{
m_queue.BeginReceive();
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}

public void MessageArrived(Object source,
ReceiveCompletedEventArgs
args)
{
MessageQueue queue = source as MessageQueue;
Message message = queue.EndReceive(args.AsyncResult);

CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}

private void AddItem(String strID)
{
Message message = m_queue.PeekById(strID);
CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}
}



Are you running the following line:
MessageQueue.Exists(@"david-1\private$\callerid") on a remote machine
(not
on
david-1)? if so this is not supported for private queues. Checking
the
existence of remote queues can only be done if the queue is public -
in
which
case active directory is required.

When executing the Exists method on a local machine the proper syntax
is:
MessageQueue.Exists(@".\private$\callerid").

Period '.' meaning localhost machine.


 
S

Simon Hart [MVP]

Yes you need a domain server with active directory which is pretty standard
stuff. You don't necessarily need both computers to be part of the same
domain, they can be on different domains, but in this case there must be a
domain trust relationship in place.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


David said:
And the two computers communicating must be a member of that domain and not
a workgroup computer in order to send and receive messages?

David said:
Does a public queue require a domain server to be in place, that is, a
server that has Active Directory?

Simon Hart said:
You can only post messages to a remote private queue. You can't peek
them, or
call the BeginReceive, Receive and register the ReceiveCompleted event
handler.

Sounds like you need to define a public queue instead of a private one.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


:

Here is some code. The m_queue.BeginReceive method gets called, but
after a few seconds it throws an exception which is caught, but the ex
variable is null. My MessageArrived method is never called either even
though I have added it to the ReceiveCompleted event. Now I dont know
what
to do. This is pretty darn simple code. I can see two messages in the
queue
on david-1. I can run the server app on david-1 at the same time as the
remote side is running. The server app creates new entries but still the
MessageArrived handler is not called and a bogus exception is thrown.

Ideas why this does not work?

public partial class Form1 : Form
{
private MessageQueue m_queue;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
string deviceIP = String.Empty;
IPAddress[] addresses =
Dns.GetHostEntry("david-1").AddressList;
for (int i = 0; i < addresses.Length; ++i)
{
IPAddress addr = addresses;
if (addr.AddressFamily ==
AddressFamily.InterNetwork)
{
deviceIP = addr.ToString();
break;
}
}
if (deviceIP == String.Empty)
{
MessageBox.Show("Unable to retrieve Device IP");
Close();
return;
}

String strPath =
String.Format(@"FormatName:DIRECT=TCP:{0}\PRIVATE$\CallerID",
deviceIP);
m_queue = new MessageQueue(strPath);

if (m_queue != null)
{
System.Type[] types = new Type[1];
types[0] = typeof(CallerIDClient.CallerID);
m_queue.Formatter = new XmlMessageFormatter(types);

try
{
m_queue.ReceiveCompleted += new
ReceiveCompletedEventHandler(MessageArrived);
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
Close();
}

Thread t1 = new Thread(PeekMessages);
t1.IsBackground = true;
t1.Start();
}
else
{
MessageBox.Show("Queue not created");
Close();
}
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}

private void PeekMessages()
{
while (true)
{
try
{
m_queue.BeginReceive();
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}

public void MessageArrived(Object source,
ReceiveCompletedEventArgs
args)
{
MessageQueue queue = source as MessageQueue;
Message message = queue.EndReceive(args.AsyncResult);

CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}

private void AddItem(String strID)
{
Message message = m_queue.PeekById(strID);
CallerIDClient.CallerID callerid = message.Body as
CallerIDClient.CallerID;
if (callerid != null)
{
ListViewItem lvi = new ListViewItem(callerid.Name);
lvi.SubItems.Add(callerid.Number);
listView1.Items.Add(lvi);
}
}
}



Are you running the following line:
MessageQueue.Exists(@"david-1\private$\callerid") on a remote machine
(not
on
david-1)? if so this is not supported for private queues. Checking the
existence of remote queues can only be done if the queue is public -
in
which
case active directory is required.

When executing the Exists method on a local machine the proper syntax
is:
MessageQueue.Exists(@".\private$\callerid").

Period '.' meaning localhost machine.


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top