调用MSMQ出错,谁能帮忙?

tanweish 2003-07-04 09:23:18
System.Messaging.MessageQueueException: 工作组安装计算机不支持该操作。
at System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath(String queuePath, Boolean throwException)
at System.Messaging.MessageQueue.get_FormatName()
at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Send(Object obj)
at MyMQ.MyNewQueue.SendMessageTransactional() in d:\c#\mymq\form1.cs:line 141

谢谢
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiujoe 2003-09-11
  • 打赏
  • 举报
回复
应该是你这行代码写错了,少写了一个“\”,被当成了公共队列,所以报错
System.Messaging .MessageQueue(".\\private$\tanweish");
改为
System.Messaging .MessageQueue(".\\private$\\tanweish");
应该可以的

matboy 2003-09-10
  • 打赏
  • 举报
回复
我也碰到了同样的问题。colin666(边缘) ,你知道就说出来啊
tanweish 2003-07-04
  • 打赏
  • 举报
回复
出错程序:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Messaging ;
using System.Messaging ;
using System.ComponentModel ;



namespace MyMQ
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///

public class QueueWriterForm : System.Windows.Forms.Form
{
private bool StopWriteingFlag = false;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;

int NUMBER_THREADS = 1; //Number of threads to create

public QueueWriterForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}


#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(272, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(272, 160);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 24);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// QueueWriterForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(413, 209);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.textBox1});
this.Name = "QueueWriterForm";
this.Text = "Queue Listener";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new QueueWriterForm());
}

private void button1_Click(object sender, System.EventArgs e)
{

// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();

// Send a message to a queue.
myNewQueue.SendMessageTransactional();

// Receive a message from a queue.
myNewQueue.ReceiveMessageTransactional();


}
}

public class MyNewQueue
{

//**************************************************
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a transactional queue.
//**************************************************



//**************************************************
// Sends a message to a queue.
//**************************************************

public void SendMessageTransactional()
{

// Connect to a queue on the local computer.
System.Messaging .MessageQueue myQueue = new
System.Messaging .MessageQueue(".\\private$\tanweish");

try
{
// Send a message to the queue.
//if (myQueue.Transactional == true)
//{
// myQueue.Send("My Message Data.", new
// MessageQueueTransaction())
//}
myQueue.Send("My Message Data.");
}
catch(MessageQueueException e)
{
Console.WriteLine(e.ToString ());
}

return;
}


//**************************************************
// Receives a message containing an Order.
//**************************************************

public void ReceiveMessageTransactional()
{
// Connect to a transactional queue on the local computer.
System.Messaging .MessageQueue myQueue = new
System.Messaging .MessageQueue(".\\private$\tanweish");

// Set the formatter.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});

// Create a transaction.
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();

try
{
// Begin the transaction.
myTransaction.Begin();


// Receive the message.
System.Messaging.Message myMessage = myQueue.Receive(myTransaction);
String myOrder = (String) myMessage.Body;

// Display message information.
Console.WriteLine(myOrder);

// Commit the transaction.
myTransaction.Commit();

}

catch (MessageQueueException e)
{
// Handle nontransactional queues.
if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.TransactionUsage)
{
Console.WriteLine("Queue is not transactional.");
}

// Else catch other sources of MessageQueueException.

// Roll back the transaction.
myTransaction.Abort();
}

// Catch other exceptions as necessary, such as
// InvalidOperationException, thrown when the formatter
// cannot deserialize the message.

return;
}
}

}
tanweish 2003-07-04
  • 打赏
  • 举报
回复
太多了,好像对工作组安装计算机的说明不多,我都照做了
colin666 2003-07-04
  • 打赏
  • 举报
回复
你应该先看看WINDOWS帮助里面的关于MSMQ的说明,写的很清楚了.

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧