469,333 Members | 4,490 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,333 developers. It's quick & easy.

Starting an application using MSMQ from Windows service

Hi,

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
queue
messageQueue = new MessageQueue(queuePath);
}
else
{
// No, create the queue and cache the returned
object
messageQueue = MessageQueue.Create(queuePath);
}

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

messageQueue.Formatter = new
XmlMessageFormatter(expectedTypes);

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;

try
{
messageQueue = (MessageQueue)sender;

...
}
catch (Exception ee)
{
ErrorLogger.Instance.LogMessage(EVENT_SRC,
EventLogEntryType.Error, ee.Message, ee.StackTrace);
}
finally
{
if (messageQueue != null)
{
// Restart the asynchronous receive operation.
messageQueue.BeginReceive();
}
}

}

/////////////////////////////////////////////////////////////////////////

Thanks
Dominique
Mar 21 '08 #1
0 1531

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
1 post views Thread by CARIGAR | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.