471,892 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,892 software developers and data experts.

Starting an application using MSMQ from Windows service


I have a problem when I try to start an application using MSMQ from a
Windows Service. The application runs on a server. The client send a
message to a public queue created on the server, the server process
the request and return the result to a public queue on the client.
All is working fine if I start my application directly on the server.
But we want to embed the start of the application into a Windows
service. When I install the service that I create for this, I use the
account LocalSystem. On the server, I add the users "SYSTEM" and
"NETWORK SERVICE" with full control on my message queue.

All it seems to be executed correctly, I log many events and
everything is executed without errors. The service start the process
and the process is intiliized correctly. The only problem that I have
is that I never receive messages into my application when it is
started from the Windows service. The message is in the Queue on the
server but the event ReceiveCompleted seems to never be called.

Did someone have any idea why a never receive the message???

Here is the code that I wrote to create the message queue on the
server side:


public MessageQueueManager()
string mesageQueueName =

System.Configuration.ConfigurationSettings.AppSett ings["MessageQueueName"];
//Construct the path of the queue
string queuePath = ".\\mesageQueueName";

MessageQueue messageQueue;
//Init the message queue
if (MessageQueue.Exists(queuePath) == true)
// Yes, then create an object representing the
messageQueue = new MessageQueue(queuePath);
// No, create the queue and cache the returned
messageQueue = MessageQueue.Create(queuePath);

// Create an array of types expected in the message
Type[] expectedTypes = new Type[] { typeof(string) };

messageQueue.Formatter = new

messageQueue.ReceiveCompleted += new
ReceiveCompletedEventHandler(messageQueue_ReceiveC ompleted);

//Start the asynchronous receive operation.
IAsyncResult ar = messageQueue.BeginReceive();

static void messageQueue_ReceiveCompleted(object sender,
ReceiveCompletedEventArgs e)
// Cast the state object to MessageQueue
MessageQueue messageQueue = null;

messageQueue = (MessageQueue)sender;

catch (Exception ee)
EventLogEntryType.Error, ee.Message, ee.StackTrace);
if (messageQueue != null)
// Restart the asynchronous receive operation.



Mar 21 '08 #1
0 1595

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Przemo | last post: by
14 posts views Thread by Webbee | last post: by
7 posts views Thread by Ahmed Perlom | last post: by
reply views Thread by YellowAndGreen | last post: by

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.