本文整理匯總了C#中System.Messaging.XmlMessageFormatter類的典型用法代碼示例。如果您正苦於以下問題:C# XmlMessageFormatter類的具體用法?C# XmlMessageFormatter怎麽用?C# XmlMessageFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XmlMessageFormatter類屬於System.Messaging命名空間,在下文中一共展示了XmlMessageFormatter類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Messaging;
public class Server{
public static void Main(){
Console.WriteLine("Processing Orders");
string queuePath = ".\\orders";
EnsureQueueExists(queuePath);
MessageQueue queue = new MessageQueue(queuePath);
((XmlMessageFormatter)queue.Formatter).TargetTypeNames = new string[]{"Order"};
while(true){
Order newOrder = (Order)queue.Receive().Body;
newOrder.ShipItems();
}
}
// Creates the queue if it does not already exist.
public static void EnsureQueueExists(string path){
if(!MessageQueue.Exists(path)){
MessageQueue.Create(path);
}
}
}
示例2: ShipItems
//引入命名空間
using System;
public class Order{
public int itemId;
public int quantity;
public string address;
public void ShipItems(){
Console.WriteLine("Order Placed:");
Console.WriteLine("\tItem ID : {0}",itemId);
Console.WriteLine("\tQuantity : {0}",quantity);
Console.WriteLine("\tShip To : {0}",address);
// Add order to the database.
/* Insert code here. */
}
}
示例3: Main
//引入命名空間
using System;
using System.Messaging;
class Client{
public static void Main(){
string queuePath = ".\\orders";
EnsureQueueExists(queuePath);
MessageQueue queue = new MessageQueue(queuePath);
Order orderRequest = new Order();
orderRequest.itemId = 1025;
orderRequest.quantity = 5;
orderRequest.address = "One Microsoft Way";
queue.Send(orderRequest);
// This line uses a new method you define on the Order class:
// orderRequest.PrintReceipt();
}
// Creates the queue if it does not already exist.
public static void EnsureQueueExists(string path){
if(!MessageQueue.Exists(path)){
MessageQueue.Create(path);
}
}
}
示例4: new XmlMessageFormatter
//引入命名空間
using System;
using System.Messaging;
class MainClass
{
[STAThread]
static void Main(string[] args)
{
MessageQueue txq1 = new MessageQueue( @".\Private$\txq1" );
MessageQueue txq2 = new MessageQueue( @".\Private$\txq2" );
using ( MessageQueueTransaction mqtx = new MessageQueueTransaction() )
{
mqtx.Begin();
Message msgIn = txq1.Receive( mqtx );
msgIn.Formatter = new XmlMessageFormatter( new String[] { "System.String, mscorlib", } );
Message msgOut = new Message();
msgOut.Body = (string)msgIn.Body;
txq2.Send( msgOut, mqtx );
System.Console.WriteLine( "Aborting message: {0}", (string)msgIn.Body );
//mqtx.Abort();
mqtx.Commit();
}
}
}