自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

說明WCF消息隊列具體問題

開發(fā) 后端
信息對于消息來說是非常重要的,在WCF分為四種主要的類型,下面我就對下WCF消息隊列進行詳細的介紹吧,希望對大家有所幫助。

希望我對WCF消息隊列的一點經(jīng)驗?zāi)芙o大家?guī)韼椭瑢е耊ebDeployment出錯的原因也許還有很多,不過在你遇到錯誤時,可以先檢查一下你程序中的字符串,暫時把他們置為””,試試看。沒準就是他引起的問題啊。

MessageQueue.Create參數(shù)是存放消息隊列的位置.這個基本就完成了創(chuàng)建和發(fā)送消息的主程序.下面我們來建立一個客戶端,來訪問消息隊列,獲取消息,同樣建立一個控制臺應(yīng)用程序,

WCF消息隊列添加引用和代碼:

  1. 1namespace MSMQClient     
  2. class Program     
  3. {     
  4. static void Main(string[] args)     
  5. {     
  6. //Get public queue message     
  7. if (MessageQueue.Exists(@".FrankMSMQ"))//判斷是否存在消息隊列     
  8. {     
  9.     
  10. using(MessageQueue mq = new MessageQueue(@".FrankMSMQ"))//創(chuàng)建消息隊列對象     
  11. {     
  12. mq.Formatter = new XmlMessageFormatter(new string[] { "System.String" });//設(shè)置消息隊列的格式化器     
  13. //mq.Send("Sample Message", ":Label");     
  14. Message msg = mq.Receive();//從隊列接受消息     
  15. Console.WriteLine("Received MSMQ Message is :{0}", msg.Body);//輸出消息     
  16. }     
  17. //Console.Read();     
  18. }     
  19. //Get private queue message     
  20. if (MessageQueue.Exists(@".Private$FrankMSMQ"))//判斷私有消息是否存在     
  21. {     
  22. using (MessageQueue mq = new MessageQueue(@".Private$FrankMSMQ"))     
  23. {     
  24. mq.Formatter = new XmlMessageFormatter(new string[] { "System.String" });//設(shè)置消息隊列格式化器     
  25. //mq.Send("Sample Message", ":Label");     
  26. Message msg = mq.Receive();//接收消息     
  27. Console.WriteLine("Received MSMQ Private Message is: {0}", msg.Body);//輸出消息     
  28. }     
  29. }     
  30. Console.Read();     
  31. }     
  32. }     
  33. }  

消息接收同樣需要實例化一個WCF消息隊列對象, using(MessageQueue mq = new MessageQueue(@".FrankMSMQ"))負責創(chuàng)建WCF消息隊列對象.其次這行代碼負責設(shè)置消息隊列的格式化器,因為消息的傳遞過程中存在格式化的問題.我們接收消息的時候必須指定消息隊列的格式化屬性Formatter, 隊列才能接受消息。 #t#

XmlMessageFormatter的作用是進行消息的XML串行化.BinaryMessageFormatter則把消息格式化為二進制數(shù)據(jù)進行傳輸.ActiveXMessageFormatter把消息同樣進行二進制格式化,區(qū)別是可以使用COM讀取隊列中的消息。當然消息隊列還可以發(fā)送復雜的對象,前提是這個對象要可串行化,具體的格式取決與隊列的格式化器設(shè)置.此外消息隊列還支持事務(wù)隊列來確保消息只發(fā)送一次和發(fā)送的順序.最近在研究SOA,所以系統(tǒng)系統(tǒng)學習一下WCF消息隊列及其相關(guān)的技術(shù),以上就是這個消息隊列的基本的概念和簡單的編程實現(xiàn).

責任編輯:chenqingxiang 來源: 51CTO.com
相關(guān)推薦

2010-02-22 17:29:47

WCF跨域

2009-12-08 10:21:17

WCF地址

2009-11-09 11:15:06

WCF消息隊列

2009-12-07 09:23:05

2009-12-08 16:09:02

WCF消息

2009-12-07 16:57:39

WCF安全性

2010-04-01 15:58:55

CentOS操作系統(tǒng)

2010-03-09 17:32:45

Python數(shù)組

2009-10-16 13:04:18

網(wǎng)絡(luò)綜合布線

2009-11-09 11:31:47

WCF消息隊列

2017-10-11 15:08:28

消息隊列常見

2009-12-07 17:46:52

WCF框架

2010-02-25 14:26:48

WCF特點

2010-02-22 10:01:11

WCF消息處理

2009-12-07 18:06:46

WCF框架

2009-12-08 09:00:14

WCF線程

2009-12-08 10:35:29

WCF地址

2009-12-21 16:04:45

WCF Dispose

2009-12-07 10:46:08

WCF框架

2009-12-07 18:43:29

WCF框架
點贊
收藏

51CTO技術(shù)棧公眾號