WCF Learning Journey----Basics of MSMQ

Source: Internet
Author: User
Tags msmq

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.