Csharp/C Sharp/Web Services/MessageQueue
MessageQueue.Create
using System;
using System.Messaging;
class Program {
static void Main(string[] args) {
using (MessageQueue queue = MessageQueue.Create(@".\MyNewPublicQueue")) {
Console.WriteLine("Queue created:");
Console.WriteLine("Path: {0}", queue.Path);
Console.WriteLine("FormatName: {0}", queue.FormatName);
}
Console.ReadLine();
}
}
MessageQueue: Exists
using System;
using System.Messaging;
[Serializable]
class MyMessage {
private string data;
public MyMessage(string data) {
this.data = data;
}
public override string ToString() {
return data;
}
}
class Program {
static void Main(string[] args) {
try {
if (!MessageQueue.Exists(@".\Private$\MyPrivateQueue")) {
MessageQueue.Create(@".\Private$\MyPrivateQueue");
}
MessageQueue queue = new MessageQueue(@".\Private$\MyPrivateQueue");
queue.Formatter = new BinaryMessageFormatter();
queue.Send("Sample Message", "Label");
MyMessage m = new MyMessage("xxx");
queue.Send(m, "Binary Test");
} catch (MessageQueueException ex) {
Console.WriteLine(ex.Message);
}
}
}