How to view MSMQ message contents from WCF Service? RRS feed

  • Question

  • Hello!

    I am new to WCF and set up a very simple service program.  All I want to do is have my service pick up the message off the queue and have my method simply display content of the message on the queue.  I cannot find any examples of this.  For example, putting a String message "Hello there!" on the queue, how can my service pull that off the queue using WCF and just say "You put on the queue {0}", currentMessage?  Are there any classes that let you actually see the message in WCF?

    Here is what I have so far:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceModel;
    using ServiceModelEx;
    using System.Messaging;
    using System.Diagnostics;
    using System.Transactions;
    using System.Configuration;
    namespace MyTestServiceProg
        public interface IMyContract
            void MyGetMessageMethod();
        [ServiceBehavior(InstanceContextMode= InstanceContextMode.PerCall)]
        public class MyService : IMyContract
            public void MyGetMessageMethod()
                Transaction transaction = Transaction.Current;
                Debug.Assert(transaction.TransactionInformation.DistributedIdentifier != Guid.Empty);
            static void Main(string[] args)
                // Get MSMQ queue name from app settings in configuration
                string queueName = ConfigurationManager.AppSettings["queueName"];
                string baseAddress = ConfigurationManager.AppSettings["baseAddress"];
                // Create the transacted MSMQ queue if necessary.
                if (!MessageQueue.Exists(queueName))
                    MessageQueue.Create(queueName, true);
                using (ServiceHost serviceHost = new ServiceHost(typeof(MyService), new Uri(baseAddress)))
                    Console.WriteLine("The MyService service is open...");
                    Console.WriteLine("Press enter to stop the service.");
     Here is my app config file:
    <?xml version="1.0" encoding="utf-8" ?>
            <add key="queueName" value=".\private$\myfirstq" />
            <add key="baseAddress" value="net.msmq://localhost/private/myfirstq"/>
                <service name="MyTestServiceProg.MyService" >
                    <binding name="NoMSMQSecurity" exactlyOnce="false">
                        <security mode="None"></security>

    The service runs fine, but no clue how to get the message and see the contents of it, any ideas?

    Thanks in advance!

    Friday, April 3, 2009 1:20 PM


All replies