当前位置: 首页>>代码示例>>C#>>正文


C# XmlMessageFormatter类代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:.NET开发者,项目名称:System.Messaging,代码行数:28,代码来源:XmlMessageFormatter

示例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. */
     }
 }
开发者ID:.NET开发者,项目名称:System.Messaging,代码行数:20,代码来源:XmlMessageFormatter

示例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);
         }
     }
 }
开发者ID:.NET开发者,项目名称:System.Messaging,代码行数:29,代码来源:XmlMessageFormatter

示例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();
    }
  }
}
开发者ID:C#程序员,项目名称:System.Messaging,代码行数:26,代码来源:XmlMessageFormatter


注:本文中的System.Messaging.XmlMessageFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。