Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I throttle a WCF MSMQ endpoint?
    text
    copied!<p>I'm new to WCF and just learning how to get a client to talk to a host (both in console applications) using MSMQ.</p> <p>I want to be able to send messages from client to host and have the host pick them up immediately or, if the host is stopped, to continue where it left off when it is restarted.</p> <p>I've got this almost working but I find that when I restart the host with ten messages in the queue, the messages are not processed in the queue order. I assume there's some multithreading going on that makes them appear out of order. I'd like to be able to limit the WCF service to processing one message at a time to stop this happening (unless there's a better solution).</p> <p>It's essential to a system that I'm about to work on that the MSMQ messages are processed in order and not in parallel.</p> <p>The code for my service contract is:</p> <pre><code>[ServiceContract(Namespace = "http://www.heronfoods.com/DemoService")] public interface IDemoService { [OperationContract(IsOneWay = true)] void SendMessage(string message); } </code></pre> <p>For the Service contract implementation I've got this. (The console output is because this is a demo app for me to learn from):</p> <pre><code>public class DemoService : IDemoService { public void SendMessage(string message) { Console.WriteLine("{0} : {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), message); } } </code></pre> <p>My host application is a console application with the following code:</p> <pre><code>class Program { static void Main(string[] args) { Console.Title = "WCF Host"; using (var host = new ServiceHost(typeof(Library.DemoService))) { var endpoint = new ServiceEndpoint( ContractDescription.GetContract(typeof(Library.IDemoService)), new NetMsmqBinding(NetMsmqSecurityMode.None), new EndpointAddress("net.msmq://localhost/private/test")); host.AddServiceEndpoint(endpoint); host.Open(); Console.WriteLine("Host Active"); Console.ReadLine(); } } } </code></pre> <p>The client is equally simple:</p> <pre><code>class Program { static void Main(string[] args) { Console.Title = "WCF Client"; IDemoService proxy = ChannelFactory&lt;IDemoService&gt;.CreateChannel( new NetMsmqBinding(NetMsmqSecurityMode.None), new EndpointAddress("net.msmq://localhost/private/test") ); do { string msg = Console.ReadLine(); if (msg=="") break; else proxy.SendMessage(msg); } while (true); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload