Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the solution for WCF message queuing

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What is the solution of WCF message queue? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Messages are the source of information. In WCF, message queues are divided into public queues, private queues, management queues and response queues. Let's simply analyze WCF message queues. The MessageQueue.Create parameter is the location where the message queue is stored. This basically completes the main program that creates and sends messages. Let's set up a client to access the message queue, get the message, also set up a console application, and add references and code:

1namespace MSMQClient class Program {static void Main (string [] args) {/ / Get public queue message if (MessageQueue.Exists (@ ".FrankMSMQ")) / / determine whether there is a message queue {using (MessageQueue mq = new MessageQueue (@ ".FrankMSMQ")) / / create a message queue object {mq.Formatter = new XmlMessageFormatter (new string [] {"System.String"}) / / set the formatter of the message queue / / mq.Send ("Sample Message", ": Label"); Message msg = mq.Receive (); / / accept message Console.WriteLine ("Received MSMQ Message is: {0}", msg.Body) from the queue; / / output message} / / Console.Read () } / / Get private queue message if (MessageQueue.Exists (@ ".Private $FrankMSMQ")) / / determine whether a private message exists {using (MessageQueue mq = new MessageQueue (@ ".Private $FrankMSMQ")) {mq.Formatter = new XmlMessageFormatter (new string [] {"System.String"}); / / set message queuing formatter / / mq.Send ("Sample Message", ": Label"); Message msg = mq.Receive () / / receive message Console.WriteLine ("Received MSMQ Private Message is: {0}", msg.Body); / / output message}} Console.Read ();}

Message receiving also needs to instantiate a WCF message queue object, and using (MessageQueue mq = new MessageQueue (@ ".FrankMSMQ")) is responsible for creating WCF message queue objects. Secondly, mq.Formatter = new XmlMessageFormatter (new string [] {"System.String"}) is responsible for setting the formatter of the message queue, because there is a formatting problem in the message delivery process. When we receive a message, we must specify the formatting property Formatter of the message queue before the queue can accept the message.

The function of XmlMessageFormatter is to serialize messages. XmlMessageFormatter formats messages into binary data for transmission. ActiveXMessageFormatter also formats messages in binary format. The difference is that you can use COM to read messages in the queue. Of course, message queues can also send complex objects, as long as the object can be serialized, and the specific format depends on the formatter setting of the queue. In addition, message queuing supports transaction queues to ensure that messages are sent only once and in order. Recently, I have been studying SOA, so I will systematically learn WCF and its related technologies.

After reading the above, have you mastered the solution of WCF message queuing? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report