本文整理汇总了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();
}
}
}