MSMQ - WCF Architecture

Hi,

I was wondering, when I use MSMQ (netMsmqBinding) in WCF, how WCF gets the message from the queue? Does WCF periodically check the queue? Or are there mechanism used by WCF to notify the WCF Runtime for incoming message?

Another thing is about the ServiceHost class. When I initialize ServiceHost class, and open it, the WCF service should be up and running right? My question is, does WCF create separate thread to process the message, or is WCF using the existing thread (the one that initialize the ServiceHost)?

Any documentation on it?

Thanks

Best Regards, Ferry Mulyono

[626 byte] By [FerryMulyono] at [2008-1-6]
# 1

As for your second question, when you call Open() on a ServiceHost, it does it in a different thread. But for your first question, I think Sorin will be answering it shortly.

-James

JamesOsborne-MSFT at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2

Hi,

WCF will constantly and indefinitely monitor queues so long as the service host is open. So as soon as messages arrive in a queue, if there is a service with an endpoint listening to the queue, the messages will be immediately received and dispatched. Likewise, as long as there are messages in the queue, your service will continuously receive them.

James is right and the service instance will run in a separate thread. You can also have multiple threads receiving messages from the same queue. A good optimization for high-throughput transactional queues is to turn on Batching and have multiple concurrent batches receive the messages. Have a look here for Batching. Look at the Concurrency section in the doc for more details.

SorinAlexander-MSFT at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3

Hi, I followed the MSDN example msmq2wcf and started my service in a console program to listen to the private queue. My client is sending messages to the queue and I can verify it when looking at the queued messages. However, the service is not getting triggered. Can anyone shed some light on this?

Here is my code snippet:

Contract:

[ServiceContract]

[ServiceKnownType(typeof(byte[]))]

public interface IFileProcessor

{

[OperationContract(IsOneWay = true,Action = "*")]

void SubmitFile(MsmqMessage<byte[]> msg);

}

Notice my action= "*", that means the dispatcher will call the method at all times once the messages are coming, right?

public class FileProcessorService : IFileProcessor //, IContractBehavior

{

[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]

public void SubmitFile(MsmqMessage<byte[]> msg)

{

byte[] content = (byte[])msg.Body;

Console.WriteLine("Processing file bytes {0} ", content.Length);

string label = msg.Label;

Console.WriteLine("message label {0}", label);

using (FileStream binWriter =

new FileStream(@"C:\temp\Test.png", FileMode.Create) )

{

binWriter.Write(content, 0, content.Length);

}

}

....

KZS at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified