本文整理汇总了C#中System.Messaging.MessageQueue.Send方法的典型用法代码示例。如果您正苦于以下问题:C# MessageQueue.Send方法的具体用法?C# MessageQueue.Send怎么用?C# MessageQueue.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Messaging.MessageQueue
的用法示例。
在下文中一共展示了MessageQueue.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnAdd_Click
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
string queueName = ConfigurationManager.AppSettings["MSMQLocation"];
MessageQueue rmTxnQ = new MessageQueue(queueName);
rmTxnQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(ProcessMessage) });
foreach (ListBoxItem itm in files.Items)
{
MessageQueueTransaction msgTx = new MessageQueueTransaction();
msgTx.Begin();
try
{
string argument = "-i \"{0}\" -o \"{1}\" --preset \"" + ConfigurationManager.AppSettings["HandbrakePreset"] + "\"";
string destination = txtDestination.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(itm.ToolTip.ToString()) + ".m4v";
ProcessMessage p = new ProcessMessage() { CommandLine = argument, DestinationURL = destination, OrignalFileURL = itm.ToolTip.ToString() };
rmTxnQ.Send(p, msgTx);
results.Items.Insert(0, string.Format("{0} added to queue", p.OrignalFileURL));
msgTx.Commit();
}
catch (Exception ex)
{
results.Items.Insert(0, ex.Message);
msgTx.Abort();
}
}
}
示例2: ByMSMQ
static void ByMSMQ()
{
Console.WriteLine("Opening MSMQ...");
//messageQueue = !MessageQueue.Exists(QueueName) ? MessageQueue.Create(QueueName) : new MessageQueue(QueueName);4
messageQueue = new MessageQueue(QueueName);
Console.WriteLine("Server is ready");
Console.WriteLine("Launch client app");
RSA_public_key_receive();
Console.WriteLine("Receiving open RSA-key...");
Console.WriteLine("Making DES-key...");
des_provider = new DESCryptoServiceProvider();
des_provider.GenerateKey();
des_provider.GenerateIV();
Console.WriteLine("Crypt DES-key with open RSA-key...");
DES_key = Encrypt_RSA(des_provider.Key);
Console.WriteLine("Sending encrypted DES-key and initialization vector(IV)...");
messageQueue.Send(DES_key);
messageQueue.Send(des_provider.IV);
Console.WriteLine("Getting data from Access...");
GetData();
Console.WriteLine("Crypt data...");
var myMemoryStream = new MemoryStream();
EncryptAndSerialize(myMemoryStream, data_to_recieve.ToArray());
Console.WriteLine("Transfering data...");
//Console.WriteLine("length = " + myMemoryStream.Length);
messageQueue.Send(myMemoryStream.ToArray());
Console.WriteLine("Successfull");
Console.ReadKey();
}
示例3: Main
static void Main(string[] args)
{
Console.WriteLine("Simple Text");
Console.WriteLine("Input for MSMQ Message:");
string input = Console.ReadLine();
MessageQueue queue = new MessageQueue(@".\private$\test");
queue.Send(input);
Console.WriteLine("Press Enter to continue");
Console.ReadLine();
Console.WriteLine("Output for MSMQ Queue");
Console.WriteLine(queue.Receive().Body.ToString());
Console.ReadLine();
Console.WriteLine("Complex Text");
User tester = new User();
tester.Birthday = DateTime.Now;
tester.Name = "Test Name";
queue.Send(tester);
Console.WriteLine("Output for MSMQ Queue");
User output = (User)queue.Receive().Body;
Console.WriteLine(output.Birthday.ToShortDateString());
Console.ReadLine();
}
示例4: StringMessageFormatter
public void StringMessageFormatter()
{
var ids = new List<string>();
var mq = new MessageQueue(@".\private$\QMM_");
mq.Formatter = new StringMessageFormatter();
mq.Send("12345");
mq.Send("23456");
mq.Dispose();
mq = null;
mq = new MessageQueue(@".\private$\QMM_");
for (int i = 0; i < 3; i++)
{
Message msg = null;
try
{
msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
if (msg != null)
{
msg.Formatter = new StringMessageFormatter();
Console.WriteLine(msg.Body);
}
}
}
示例5: WriteReadMessage
public void WriteReadMessage()
{
var ids = new List<string>();
var mq = new MessageQueue(@".\private$\QMM_");
mq.Send("12345");
mq.Send("23456");
var msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
if (msg != null)
Console.WriteLine(msg.Body);
mq.Dispose();
mq = null;
mq = new MessageQueue(@".\private$\QMM_");
msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
if (msg != null)
{
msg.Formatter = new XmlMessageFormatter(new Type[] {typeof (string)});
Console.WriteLine(msg.Body);
}
}
示例6: Main
static void Main(string[] args)
{
//Connect to the queue
MessageQueue orderQueue = new MessageQueue("FormatName:Direct=OS:" + ConfigurationManager.AppSettings["orderQueueName"]);
// Create the purchase order
PurchaseOrder po = new PurchaseOrder();
po.customerId = "somecustomer.com";
po.poNumber = Guid.NewGuid().ToString();
PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
lineItem1.productId = "Blue Widget";
lineItem1.quantity = 54;
lineItem1.unitCost = 29.99F;
PurchaseOrderLineItem lineItem2 = new PurchaseOrderLineItem();
lineItem2.productId = "Red Widget";
lineItem2.quantity = 890;
lineItem2.unitCost = 45.89F;
po.orderLineItems = new PurchaseOrderLineItem[2];
po.orderLineItems[0] = lineItem1;
po.orderLineItems[1] = lineItem2;
// submit the purchase order
Message msg = new Message();
msg.Body = po;
msg.Label = "SubmitPurchaseOrder";
//Submit an Order.
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
orderQueue.Send(msg, MessageQueueTransactionType.Automatic);
// Complete the transaction.
scope.Complete();
}
Console.WriteLine("Placed the order:{0}", po);
// submit the purchase order
Message msg2 = new Message();
msg2.Body = po.poNumber;
msg2.Label = "CancelPurchaseOrder";
//Cancel the Order.
using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Required))
{
orderQueue.Send(msg2, MessageQueueTransactionType.Automatic);
// Complete the transaction.
scope2.Complete();
}
Console.WriteLine("Cancelled the Order: {0}", po.poNumber);
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例7: Send
/// <summary>
/// Sends the given <paramref name="message"/>
/// </summary>
public void Send(TransportMessage message, SendOptions sendOptions)
{
var address = sendOptions.Destination;
var queuePath = NServiceBus.MsmqUtilities.GetFullPath(address);
var transactionType = GetTransactionTypeForSend();
if (message.TimeToBeReceived < MessageQueue.InfiniteTimeout && WillUseTransactionThatSupportsMultipleOperations(sendOptions.EnlistInReceiveTransaction, transactionType))
{
throw new Exception($"Failed to send message to address: {address.Queue}@{address.Machine}. Sending messages with a custom TimeToBeReceived is not supported on transactional MSMQ.");
}
try
{
using (var q = new MessageQueue(queuePath, false, Settings.UseConnectionCache, QueueAccessMode.Send))
{
using (var toSend = NServiceBus.MsmqUtilities.Convert(message))
{
toSend.UseDeadLetterQueue = Settings.UseDeadLetterQueue;
toSend.UseJournalQueue = Settings.UseJournalQueue;
toSend.TimeToReachQueue = Settings.TimeToReachQueue;
var replyToAddress = sendOptions.ReplyToAddress ?? message.ReplyToAddress;
if (replyToAddress != null)
{
toSend.ResponseQueue = new MessageQueue(NServiceBus.MsmqUtilities.GetReturnAddress(replyToAddress.ToString(), address.ToString()));
}
if (sendOptions.EnlistInReceiveTransaction && UnitOfWork.HasActiveTransaction())
{
q.Send(toSend, UnitOfWork.Transaction);
}
else
{
q.Send(toSend, transactionType);
}
}
}
}
catch (MessageQueueException ex)
{
if (ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueNotFound)
{
var msg = address == null
? "Failed to send message. Target address is null."
: string.Format("Failed to send message to address: [{0}]", address);
throw new QueueNotFoundException(address, msg, ex);
}
ThrowFailedToSendException(address, ex);
}
catch (Exception ex)
{
ThrowFailedToSendException(address, ex);
}
}
示例8: SendtoMsmq
void SendtoMsmq(MessageQueue msmqQueue, Message msmqMessage)
{
if (Transaction.Current == null)
{
msmqQueue.Send(msmqMessage, MessageQueueTransactionType.Single);
}
else
{
msmqQueue.Send(msmqMessage, MessageQueueTransactionType.Automatic);
}
}
示例9: Send
/// <summary>
/// Sends the given <paramref name="message"/>
/// </summary>
public void Send(TransportMessage message, SendOptions sendOptions)
{
var address = sendOptions.Destination;
var queuePath = NServiceBus.MsmqUtilities.GetFullPath(address);
try
{
using (var q = new MessageQueue(queuePath, false, Settings.UseConnectionCache, QueueAccessMode.Send))
{
using (var toSend = NServiceBus.MsmqUtilities.Convert(message))
{
toSend.UseDeadLetterQueue = Settings.UseDeadLetterQueue;
toSend.UseJournalQueue = Settings.UseJournalQueue;
var replyToAddress = sendOptions.ReplyToAddress ?? message.ReplyToAddress;
if (replyToAddress != null)
{
toSend.ResponseQueue = new MessageQueue(NServiceBus.MsmqUtilities.GetReturnAddress(replyToAddress.ToString(), address.ToString()));
}
if (sendOptions.EnlistInReceiveTransaction && UnitOfWork.HasActiveTransaction())
{
q.Send(toSend, UnitOfWork.Transaction);
}
else
{
q.Send(toSend, GetTransactionTypeForSend());
}
}
}
}
catch (MessageQueueException ex)
{
if (ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueNotFound)
{
var msg = address == null
? "Failed to send message. Target address is null."
: string.Format("Failed to send message to address: [{0}]", address);
throw new QueueNotFoundException(address, msg, ex);
}
ThrowFailedToSendException(address, ex);
}
catch (Exception ex)
{
ThrowFailedToSendException(address, ex);
}
}
示例10: Setup
public void Setup()
{
if (!MessageQueue.Exists(_queueName))
MessageQueue.Create(_queueName, true);
_queue = new MessageQueue(_queueName, false, true, QueueAccessMode.SendAndReceive);
_queue.Purge();
_firstMsg = new Message {Label = 0.Days().FromUtcNow().ToString()};
_secondMsg = new Message {Label = 1.Days().FromUtcNow().ToString()};
_queue.Send(_firstMsg, MessageQueueTransactionType.Single);
_queue.Send(_secondMsg, MessageQueueTransactionType.Single);
}
示例11: An_undecipherable_blob_should_be_discarded
public void An_undecipherable_blob_should_be_discarded()
{
var formatName = Endpoint.Address.Uri.GetInboundFormatName();
using (var queue = new MessageQueue(formatName, QueueAccessMode.Send))
{
queue.Send("This is just crap, it will cause pain");
}
try
{
Endpoint.Receive(context =>
{
IConsumeContext<PingMessage> pingContext;
context.TryGetContext(out pingContext);
Assert.Fail("Receive should have thrown a serialization exception");
return null;
}, TimeSpan.Zero);
}
catch (Exception ex)
{
Assert.Fail("Did not expect " + ex.GetType() + " = " + ex.Message);
}
Assert.AreEqual(0, EndpointAddress.GetMsmqMessageCount(), "Endpoint was not empty");
Assert.AreEqual(1, ErrorEndpointAddress.GetMsmqMessageCount(), "Error endpoint did not contain bogus message");
}
示例12: SendMessageToQueue
public void SendMessageToQueue(string queueName, CallDisposition data)
{
var msMq = new MessageQueue(queueName);
var myMessage = new System.Messaging.Message();
myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(CallDisposition) });
myMessage.Body = data;
myMessage.Label = "MessageQueue";
myMessage.UseJournalQueue = true;
myMessage.Recoverable = true;
//message send acknowledgement.
myMessage.AdministrationQueue = new MessageQueue(@".\Private$\MessageAcknowledgeQueue");
myMessage.AcknowledgeType = AcknowledgeTypes.PositiveReceive | AcknowledgeTypes.PositiveArrival;
try
{
msMq.Send(myMessage);
Console.WriteLine("Message sent successfully!");
}
catch (MessageQueueException e)
{
Console.Write(e.ToString());
}
catch (Exception e)
{
Console.Write(e.ToString());
}
finally
{
msMq.Close();
}
}
示例13: Main
static void Main()
{
Console.WriteLine("Using straight xml serialization and msmq to test interop.");
Console.WriteLine("To exit, enter 'q'. Press 'Enter' to send a message.");
string queueName = string.Format("FormatName:DIRECT=OS:{0}\\private$\\OrderServiceInputQueue", Environment.MachineName);
var label = "<CorrId></CorrId><WinIdName>UDI_MOBILE_2\\Administrator</WinIdName>";
var q = new MessageQueue(queueName);
var serializer = new XmlSerializer(typeof(OrderMessage), new[] { typeof(OrderLine) });
while ((Console.ReadLine().ToLower()) != "q")
{
var m1 = new OrderMessage
{
PurchaseOrderNumber = Guid.NewGuid().ToString(),
ProvideBy = DateTime.Now,
PartnerId = Guid.NewGuid(),
OrderLines = new[] {new OrderLine {ProductId = Guid.NewGuid(), Quantity = 10F}},
Done = true
};
var toSend = new Message();
serializer.Serialize(toSend.BodyStream, m1);
toSend.ResponseQueue = new MessageQueue(string.Format("FormatName:DIRECT=OS:{0}\\private$\\PartnerInputQueue", Environment.MachineName));
toSend.Label = label;
q.Send(toSend, MessageQueueTransactionType.Single);
Console.WriteLine("Sent order {0}", m1.PurchaseOrderNumber);
}
}
示例14: ShouldRemoveSubscriptionsInNonTransactionalMode
public async Task ShouldRemoveSubscriptionsInNonTransactionalMode()
{
var address = MsmqAddress.Parse("MsmqSubscriptionStorageQueueTests.PersistNonTransactional");
var queuePath = address.PathWithoutPrefix;
if (MessageQueue.Exists(queuePath))
{
MessageQueue.Delete(queuePath);
}
MessageQueue.Create(queuePath, false);
using (var queue = new MessageQueue(queuePath))
{
queue.Send(new Message
{
Label = "subscriber",
Body = typeof(MyMessage).AssemblyQualifiedName
}, MessageQueueTransactionType.None);
}
var storage = new MsmqSubscriptionStorage(new MsmqSubscriptionStorageQueue(address, false));
storage.Init();
await storage.Unsubscribe(new Subscriber("subscriber", "subscriber"), new MessageType(typeof(MyMessage)), new ContextBag());
using (var queue = new MessageQueue(queuePath))
{
CollectionAssert.IsEmpty(queue.GetAllMessages());
}
}
示例15: Send
public void Send(string Msg)
{
string QueuePath = ".\\private$\\SLS_Allcai_Task_Alipay_" + MessageType;
if (!MessageQueue.Exists(QueuePath))
{
return;
}
MessageQueue mq = null;
try
{
mq = new MessageQueue(QueuePath);
}
catch
{
return;
}
if (mq == null)
{
return;
}
System.Messaging.Message m = new System.Messaging.Message();
m.Body = Msg;
m.Formatter = new System.Messaging.BinaryMessageFormatter();
mq.Send(m);
}