Tôi có một MSMQ riêng được tạo trong máy cục bộ của mình. Tôi đang gửi tin nhắn đến hàng đợi bằng cách sử dụng mã C# sau. Khi tôi thay đổi hàng đợi thành giao dịch, thông báo không đạt được MSMQ. Tuy nhiên, không có ngoại lệ nào được ném trong phương thức Gửi. Tôi cần phải thay đổi gì để làm cho nó hoạt động?Tin nhắn không đạt được MSMQ khi thực hiện giao dịch
using System;
using System.Messaging;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
//Sharing violation resulted from queue being open already for exclusive receive.
MessageQueue helpRequestQueue = new MessageQueue(@".\Private$\MyPrivateQueue", false);
protected void Page_Load(object sender, EventArgs e)
{
bool isTransactionalQueue = false;
if (!System.Messaging.MessageQueue.Exists(@".\Private$\MyPrivateQueue"))
{
System.Messaging.MessageQueue.Create(@".\Private$\MyPrivateQueue", isTransactionalQueue);
}
SendMessage();
GetAllMessages();
}
private void SendMessage()
{
System.Messaging.Message theMessage = new System.Messaging.Message("TimeNow is "+DateTime.Now.ToString());
theMessage.Label = "Lijo " + DateTime.Now.ToString();
theMessage.Priority = System.Messaging.MessagePriority.Normal;
helpRequestQueue.Send(theMessage);
}
private void GetAllMessages()
{
DataTable messageTable = new DataTable();
messageTable.Columns.Add("Label");
messageTable.Columns.Add("Body");
//Set Message Filters
MessagePropertyFilter filter = new MessagePropertyFilter();
filter.ClearAll();
filter.Body = true;
filter.Label = true;
filter.Priority = true;
helpRequestQueue.MessageReadPropertyFilter = filter;
//Get All Messages
System.Messaging.Message[] messages = helpRequestQueue.GetAllMessages();
System.Messaging.XmlMessageFormatter stringFormatter = new System.Messaging.XmlMessageFormatter(new string[] { "System.String" });
for (int index = 0; index < messages.Length; index++)
{
string test = System.Convert.ToString(messages[index].Priority);
messages[index].Formatter = stringFormatter;
messageTable.Rows.Add(new string[] {messages[index].Label,messages[index].Body.ToString() });
}
Gridview1.DataSource = messageTable;
Gridview1.DataBind();
}
private void ReceiveAndProcess()
{
}
}
Tôi đoán là các giao dịch cần phải được cam kết. http://msdn.microsoft.com/en-us/library/windows/desktop/ms701273(v=vs.85).aspx –