首先要保证你正确安装消息队列
然后试试下面的代码
public void LookFirstMessage()
{
System.Messaging.MessageQueue newQueue =
new System.Messaging.MessageQueue(".\\MyQueue");
System.Messaging.Message firstMessage;
string[] types = { "System.String,mscorlib" };
firstMessage = newQueue.Peek();
firstMessage.Formatter =
new System.Messaging.XmlMessageFormatter(types);
string label = firstMessage.Label.ToString();
}
然后试试下面的代码
public void LookFirstMessage()
{
System.Messaging.MessageQueue newQueue =
new System.Messaging.MessageQueue(".\\MyQueue");
System.Messaging.Message firstMessage;
string[] types = { "System.String,mscorlib" };
firstMessage = newQueue.Peek();
firstMessage.Formatter =
new System.Messaging.XmlMessageFormatter(types);
string label = firstMessage.Label.ToString();
}
[MarshalAs(UnmanagedType.LPWStr)] string servername,
[MarshalAs(UnmanagedType.LPWStr)] string msgname,
[MarshalAs(UnmanagedType.LPWStr)] string fromname,
IntPtr buf,
[MarshalAs(UnmanagedType.U4)] uint buflen
);