Service side
Using system;using system.collections.generic;using system.linq;using system.text;using System.Messaging;namespace BaseOfWcf{ class Program { static void main (String[] args) { //if (! Messagequeue.exists (@ ". \myfirstmsmq")) { // using (Messagequeue mq = messagequeue.create (@ ". \myfirstmsmq")) // { // mq. label = "MYFIRSTMSMQ";nbsp; // console.writeline ("a public queue {0} has already been created", mq. Label); // console.writeline (path for public queue {0} is {1}, MQ. Label, mq. Path); // mq. Send ("msmq message", "learned an interesting knowledge today"); // } //} //foreach (MESSAGEQUEUE MQ in messagequeue.getpublicqueues ()) //{ // mq. Send ("Sending public message queue" + datetime.now.tolongtimestring (), "learned an interesting knowledge today"); // console.writeline ("Public message has been sent to {0}", MQ.) Path); //} while (True) { console.writeline ("*****************"); console.writeline ("***0: Create queue"); console.writeline ("***1: Send Message * * * *" ); Console.WriteLine ("***2:Purge Message * * * "); Console.WriteLine ("***3: Exit Program * * * *"); console.writeline ("*****************"); string s = console.readline (); switch (S ) { case "0": if (! Messagequeue.exists (@ ". \private$\myfirstmsmq")) { using (messagequeue mq = messagequeue.create (@ ". \private$\myfirstmsmq")) { mq. label = "MYFIRSTPRIVATEMSMQ"; console.writeline ("A private team has been createdcolumn {0} ", mq. Label); console.writeline (" The path of the private queue {0} is {1}, mq. Label, mq. Path); mq. Send ("msmq private queue message" + "learn an interesting knowledge today"); } } break; case "1": if (Messagequeue.exists (@ ". \private$\myfirstmsmq")) { messagequeue mq = new messagequeue (@ ". \private$\myfirstmsmq"); mq. Send ("Sending private message Queue" + datetime.now.tolongtimestring () + "Learn an interesting knowledge today"); console.writeline ("Private message has been sent to {0}", mq. Path); } break; case "2": if (Messagequeue.exists (@ ". \private$\myfirstmsmq")) { messagequeue mq = new messagequeue (@ ". \Private$\MYFIRSTMSMQ" ); mq. Purge (); console.writeline ("delete succeeded"); } break; case "3": environment.exit (0); break; default: console.writeline ("Incorrect input"); break; } } &nbSP;} }}
Client
Using system;using system.collections.generic;using system.linq;using system.text;using System.Messaging;namespace MSMQClient{ class Program { static void main (String[] args) { if (Messagequeue.exists (@ ". \private$\myfirstmsmq")) { using (Messagequeue mq = new messagequeue (@ ". \private$\myfirstmsmq")) { mq. Formatter = new xmlmEssageformatter (new string[] {"System.String"}); foreach (message msg in Mq. GetAllMessages ()) { console.writeline ("received message is: {0}", Msg.) Body); } message firstmsg = mq. Receive (); console.writeline ("The first message received is: {0}", firstmsg. Body); } } } }}
WCF Learning Journey----Basics of MSMQ