日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

.Net 操作MSMQ

發布時間:2025/4/5 asp.net 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .Net 操作MSMQ 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Code
下面這個類可以用來直接操作MSMQ,但有一個需要注意的是,如果你是用APS.NET或WINDOWS?SERVICE?操作MSMQ
一定要記的把MSMQ的隊列權限設成everyone完全控制,不然會訪問不了.我的程序中也增加了對這個權限的控制
mq.SetPermissions(
"Everyone",?MessageQueueAccessRights.FullControl);?//這一句就夠了
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Web;
using?System.Messaging;
namespace?SNET.Common
{
????
///?<summary>
????
///?
????
///?</summary>
????public?class?MSMQHelper
????{

????????
///?<summary>
????????
///?通過Create方法創建使用指定路徑的新消息隊列
????????
///?</summary>
????????
///?<param?name="queuePath"></param>
????????public?static?void?Createqueue(string?queuePath)
????????{
????????????
try
????????????{
????????????????
if?(!MessageQueue.Exists(queuePath))
????????????????{
????????????????????MessageQueue?mq?
=?MessageQueue.Create(queuePath,true);
????????????????????
if?(mq?!=?null)
????????????????????{
????????????????????????mq.SetPermissions(
"Everyone",?MessageQueueAccessRights.FullControl);
????????????????????}
????????????????}??????????????
????????????}
????????????
catch?(MessageQueueException?e)
????????????{
????????????????
throw?new?Exception(e.ToString());
????????????}
????????}
????????
///?<summary>
????????
///?Sends?the?message.
????????
///?</summary>
????????public?static?void?SendMessage(string?queuePath,string?strBody)
????????{
????????????MessageQueue?myQueue?
=?null;
????????????
try
????????????{
????????????????
//連接到本地的隊列
????????????????myQueue?=?new?MessageQueue(queuePath);
????????????????Message?myMessage?
=?new?Message();
????????????????myMessage.Body?
=?strBody;
????????????????myMessage.Formatter?
=?new?XmlMessageFormatter(new?Type[]?{?typeof(string)?});
????????????????
//發送消息到隊列中
????????????????myQueue.Send(myMessage);
????????????????myQueue.Dispose();
????????????}
????????????
catch?(ArgumentException?e)
????????????{
????????????????
throw?new?Exception(e.ToString());
????????????}
????????????
finally
????????????{
????????????????
if?(myQueue?!=?null)
????????????????????myQueue.Dispose();
????????????}
????????}
????????
///?<summary>
????????
///?Sends?the?message.
????????
///?</summary>
????????public?static?void?SendMessage(string?queuePath,?string?queueLable,string?strBody)
????????{
????????????MessageQueue?myQueue?
=?null;
????????????
try
????????????{
????????????????
//連接到本地的隊列
????????????????myQueue?=?new?MessageQueue(queuePath);
????????????????Message?myMessage?
=?new?Message();
????????????????myMessage.Body?
=?strBody;
????????????????
if?(queueLable?!=?null)
????????????????{
????????????????????myMessage.Label?
=?queueLable;
????????????????}
????????????????myMessage.Formatter?
=?new?XmlMessageFormatter(new?Type[]?{?typeof(string)?});
????????????????
//發送消息到隊列中
????????????????myQueue.Send(myMessage);
????????????????myQueue.Dispose();
????????????}
????????????
catch?(ArgumentException?e)
????????????{
????????????????
throw?new?Exception(e.ToString());
????????????}
????????????
finally
????????????{
????????????????
if?(myQueue?!=?null)
????????????????????myQueue.Dispose();
????????????}
????????}
????????
///?<summary>
????????
///?Receives?the?message.
????????
///?</summary>
????????
///?<param?name="QueuePath">The?queue?path.</param>
????????
///?<returns></returns>
????????public?static?string?ReceiveMessage(string?QueuePath)
????????{????????????
????????????
//連接到本地隊列
????????????MessageQueue?myQueue?=?new?MessageQueue(QueuePath);
????????????myQueue.Formatter?
=?new?XmlMessageFormatter(new?Type[]?{?typeof(string)?});
????????????
try
????????????{
????????????????
//從隊列中接收消息
????????????????Message?myMessage?=?myQueue.Receive(new?TimeSpan(0,0,6));????????????????
????????????????
string?context?=?(string)myMessage.Body;?//獲取消息的內容
????????????????return?context;

????????????}
????????????
catch?(MessageQueueException?e)
????????????{
????????????????
throw?new?Exception(e.ToString());
????????????}
????????????
catch?(InvalidCastException?e)
????????????{
????????????????
throw?new?Exception(e.ToString());
????????????}
????????????
finally
????????????{
????????????????
if?(myQueue?!=?null)?
????????????????myQueue.Dispose();
????????????}
????????????
return?"";
????????}
????????
///?<summary>
????????
///?Clears?the?message.
????????
///?</summary>
????????
///?<param?name="QueuePath">The?queue?path.</param>
????????public?static?void?ClearAllMessage(string?QueuePath)
????????{
????????????MessageQueue?myQueue?
=?null;
????????????
try
????????????{
????????????????myQueue?
=?new?MessageQueue(QueuePath);
????????????????myQueue.Purge();
????????????}
????????????
catch?(System.Exception?ex)
????????????{
????????????????
throw?new?Exception(ex.ToString());
????????????}
????????????
finally
????????????{
????????????????
if(myQueue?!=?null)
????????????????myQueue.Dispose();
????????????}
????????}
????????
///?<summary>
????????
///?Clears?the?message.
????????
///?</summary>
????????
///?<param?name="QueuePath">The?queue?path.</param>
????????public?static?void?DeleteMessage(string?QueuePath)
????????{??????????
????????????
try
????????????{???????????????
????????????????MessageQueue.Delete(QueuePath);
????????????}
????????????
catch?(System.Exception?ex)
????????????{
????????????????
throw?new?Exception(ex.ToString());
????????????}?????
????????}
????????
///?<summary>
????????
///?Gets?all?message.
????????
///?</summary>
????????
///?<param?name="QueuePath">The?queue?path.</param>
????????
///?<returns></returns>
????????public?static?List<string>?GetAllMessage(string?QueuePath)
????????{
????????????MessageQueue?myQueue?
=?null;
????????????
try
????????????{
????????????????
//連接到本地隊列
????????????????myQueue?=?new?MessageQueue(QueuePath);
????????????????Message[]?message?
=?myQueue.GetAllMessages();
????????????????XmlMessageFormatter?formatter?
=?new?XmlMessageFormatter(new?Type[]?{?typeof(string)?});
????????????????List
<string>?msg?=?new?List<string>(message.Length);
????????????????
for?(int?i?=?0;?i?<?message.Length;?i++)
????????????????{
????????????????????message[i].Formatter?
=?formatter;
????????????????????msg.Add(message[i].Body.ToString());
????????????????}
????????????????
return?msg;
????????????}
????????????
catch?(System.Exception?ex)
????????????{
????????????????
throw?new?Exception(ex.ToString());
????????????}
????????????
finally
????????????{
????????????????
if?(myQueue?!=?null)
????????????????{
????????????????????myQueue.Dispose();
????????????????}
????????????}
????????}
????????
///?<summary>
????????
///?Gets?all?message?by?enumerator.
????????
///?</summary>
????????
///?<param?name="QueuePath">The?queue?path.</param>
????????
///?<returns></returns>
????????public?static?List<string>?GetAllMessageByEnumerator(string?QueuePath)
????????{
????????????List
<string>?msgs?=?null;
????????????MessageQueue?myQueue?
=?null;
????????????
try
????????????{
????????????????
//連接到本地隊列
????????????????myQueue?=?new?MessageQueue(QueuePath);??????????????
????????????????XmlMessageFormatter?formatter?
=?new?XmlMessageFormatter(new?Type[]?{?typeof(string)?});
????????????????MessageEnumerator?enumerator?
=?myQueue.GetMessageEnumerator();
????????????????msgs?
=?new?List<string>();
????????????????
while?(enumerator.MoveNext())
????????????????{
????????????????????Message?content?
=?(Message)enumerator.Current;
????????????????????content.Formatter?
=?formatter;
????????????????????msgs.Add(content.Body.ToString());
????????????????????enumerator.RemoveCurrent();
????????????????}
????????????????
????????????}
????????????
catch?(System.Exception?ex)
????????????{
????????????????
throw?new?Exception(ex.ToString());
????????????}
????????????
finally
????????????{
????????????????
if?(myQueue?!=?null)
????????????????{
????????????????????myQueue.Dispose();
????????????????}
????????????}
????????????
return?msgs;
????????}
????}
}

轉載于:https://www.cnblogs.com/bobofsj11/archive/2009/09/02/1558568.html

總結

以上是生活随笔為你收集整理的.Net 操作MSMQ的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩极品少妇 | 美女隐私无遮挡网站 | 国产美女黄色 | 国产精品无码一区二区三区 | 欧美黄色视屏 | 日本久久一区二区 | 三上悠亚人妻中文字幕在线 | 亚洲第一成网站 | 日日噜噜噜 | 男女互操视频 | 少妇一级淫片免费放2 | 国产在线播放一区二区 | 在线色播| 少妇高潮av | 一二三区中文字幕 | 亚洲视频五区 | 日本熟女毛茸茸 | 青青草狠狠干 | 日本一区二区三区在线观看 | 新版天堂资源中文8在线 | av免费福利| 久久精品国产亚洲AV成人雅虎 | av片一区二区三区 | 女人天堂网站 | 欧美夜夜爽 | 欧日韩一区二区三区 | 在线播放黄色av | 无码国产精品一区二区免费式直播 | av一级在线| 青青青视频在线 | 欧美一区二区三区免费视频 | 黄色免费在线视频 | 日韩在线观看中文字幕 | 麻豆蜜桃在线观看 | 大咪咪av| 少妇被黑人到高潮喷出白浆 | 69视频国产 | 人妻av一区二区三区 | 男人添女人下部高潮视频 | 免费国产网站 | 永久av免费在线观看 | 欧美熟妇精品黑人巨大一二三区 | 午夜影院视频 | 精品久久影院 | 美国式禁忌1980 | 老熟妇精品一区二区三区 | 欧美日本高清视频 | 亚洲激情一区 | 最新亚洲精品 | 粉嫩久久99精品久久久久久夜 | 老熟女高潮一区二区三区 | 日韩一区免费视频 | 男同激情视频 | 亚洲综合第一页 | 日韩深夜视频 | 超91在线 | 日韩国产欧美在线观看 | 男人疯狂高潮呻吟视频 | 午夜影视在线观看 | 一区二区三区免费在线视频 | 韩国激情呻吟揉捏胸视频 | 国产亚洲毛片 | 三级艳丽杨钰莹三级 | 精品国自产拍在线观看 | 久久久免费电影 | 日本激情电影 | 一区二区三区色 | 韩国精品在线观看 | 免费看国产曰批40分钟 | 91蜜桃臀久久一区二区 | 你懂的日韩| 免费美女毛片 | 午夜影院91 | 国产在线精品播放 | 特级黄色网 | 伊人国产精品 | 久久久久色| 蜜桃成熟时李丽珍在线观看 | 欧美国产一区二区三区 | 69xx欧美 | 无遮挡的裸体按摩的视频 | 久久黄色小说 | 国产午夜无码视频在线观看 | 欧美一卡二卡三卡 | 影音先锋成人在线 | 欧洲影院| 亚洲激情久久久 | 亚洲 另类 春色 国产 | 国产伦人伦偷精品视频 | 美女扣逼喷水视频 | 美女在线免费视频 | 无码人妻精品一区二区三 | 天堂中文在线最新 | 久久黄色一级 | 91好色先生 | 久久免费一级片 | 夜夜爽天天爽 | 成人28深夜影院 | 无码人妻精品一区二区三区温州 |