Share via


XmlMessageFormatter 생성자

정의

XmlMessageFormatter 클래스의 새 인스턴스를 초기화합니다.

오버로드

XmlMessageFormatter()

대상 형식 집합을 설정하지 않고 XmlMessageFormatter 클래스의 새 인스턴스를 초기화합니다.

XmlMessageFormatter(String[])

정규화된 문자열 값의 배열로 전달된 대상 형식을 설정하여 XmlMessageFormatter 클래스의 새 인스턴스를 초기화합니다.

XmlMessageFormatter(Type[])

개체 형식의 배열로 전달된 대상 형식을 설정하여 XmlMessageFormatter 클래스의 새 인스턴스를 초기화합니다.

XmlMessageFormatter()

대상 형식 집합을 설정하지 않고 XmlMessageFormatter 클래스의 새 인스턴스를 초기화합니다.

public:
 XmlMessageFormatter();
public XmlMessageFormatter ();
Public Sub New ()

설명

이 오버 로드 생성자의 가장 많이 사용 됩니다 큐에 쓸 때 처럼 작성 하는 경우 대상 형식은 필요 하지 않습니다.

인스턴스를 사용 하 여 큐에서 메시지를 읽을 XmlMessageFormatter 설정 해야이 생성자를 사용 하 여 만든, 합니다 TargetTypeNames 또는 TargetTypes 포맷터에서 역직렬화할 형식을 알 수 있도록 하는 속성입니다.

새로 만들 때 MessageQueue, 기본값 XmlMessageFormatter 만들어지면이 인스턴스는 대상 유형으로 설정 하지 않고 합니다. 이 생성자를 사용 하 여 만든 포맷터가와 마찬가지로 큐에서 읽고 싶은 경우 포맷터 인스턴스에 대 한 대상 형식을 설정 해야 합니다.

적용 대상

XmlMessageFormatter(String[])

정규화된 문자열 값의 배열로 전달된 대상 형식을 설정하여 XmlMessageFormatter 클래스의 새 인스턴스를 초기화합니다.

public:
 XmlMessageFormatter(cli::array <System::String ^> ^ targetTypeNames);
public XmlMessageFormatter (string[] targetTypeNames);
new System.Messaging.XmlMessageFormatter : string[] -> System.Messaging.XmlMessageFormatter
Public Sub New (targetTypeNames As String())

매개 변수

targetTypeNames
String[]

제공된 메시지로부터 포맷터에 의해 역직렬화될 사용 가능한 형식의 집합을 지정하는 String 형식의 배열입니다. 이러한 값은 "MyNamespace.MyOrders, MyOrdersAssemblyName"처럼 정규화된 값이어야 합니다.

예외

targetTypeNames 매개 변수가 null인 경우

예제

#using <system.dll>
#using <system.messaging.dll>
#using <system.drawing.dll>

using namespace System;
using namespace System::Messaging;
using namespace System::Drawing;
using namespace System::IO;
ref class Order
{
public:
   int orderId;
   DateTime orderTime;
};

ref class MyNewQueue
{
public:
   static void CreateQueue( String^ queuePath )
   {
      try
      {
         if (  !MessageQueue::Exists( queuePath ) )
         {
            MessageQueue::Create( queuePath );
         }
         else
         {
            Console::WriteLine(  "{0} already exists.", queuePath );
         }
      }
      catch ( MessageQueueException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

   }

   void SendMessage()
   {
      try
      {
         // Create a new order and set values.
         Order^ sentOrder = gcnew Order;
         sentOrder->orderId = 3;
         sentOrder->orderTime = DateTime::Now;

         // Connect to a queue on the local computer.
         MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

         // Create the new order.
         Message^ myMessage = gcnew Message( sentOrder );

         // Send the order to the queue.
         myQueue->Send( myMessage );
      }
      catch ( ArgumentException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

      return;
   }

   void ReceiveMessage()
   {
      // Connect to the a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Set the formatter to indicate body contains an Order.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = Order::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );
      try
      {
         // Receive and format the message. 
         Message^ myMessage = myQueue->Receive();
         Order^ myOrder = dynamic_cast<Order^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( "Order ID: {0}", myOrder->orderId );
         Console::WriteLine( "Sent: {0}", myOrder->orderTime );
      }
      catch ( MessageQueueException^ ) 
      {
         // Handle Message Queuing exceptions.
      }
      // Handle invalid serialization format.
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

      // Catch other exceptions as necessary.
      return;
   }
};

int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Create a queue on the local computer.
   MyNewQueue::CreateQueue( ".\\myQueue" );

   // Send a message to a queue.
   myNewQueue->SendMessage();

   // Receive a message from a queue.
   myNewQueue->ReceiveMessage();
   return 0;
}
using System;
using System.Messaging;
using System.Drawing;
using System.IO;

namespace MyProject
{

    // The following example
    // sends to a queue and receives from a queue.
    public class Order
    {
        public int orderId;
        public DateTime orderTime;
    };	

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example sends and receives a message from
        // a queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Create a queue on the local computer.
            CreateQueue(".\\myQueue");
            
            // Send a message to a queue.
            myNewQueue.SendMessage();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessage();

            return;
        }

        //**************************************************
        // Creates a new queue.
        //**************************************************

        public static void CreateQueue(string queuePath)
        {
            try	
            {
                if(!MessageQueue.Exists(queuePath))
                {
                    MessageQueue.Create(queuePath);
                }
                else
                {
                    Console.WriteLine(queuePath + " already exists.");
                }
            }
            catch (MessageQueueException e)
            {
                Console.WriteLine(e.Message);
            }
        }

        //**************************************************
        // Sends an Order to a queue.
        //**************************************************
        
        public void SendMessage()
        {
            try
            {

                // Create a new order and set values.
                Order sentOrder = new Order();
                sentOrder.orderId = 3;
                sentOrder.orderTime = DateTime.Now;

                // Connect to a queue on the local computer.
                MessageQueue myQueue = new MessageQueue(".\\myQueue");

                // Create the new order.
                Message myMessage = new Message(sentOrder);

                // Send the order to the queue.
                myQueue.Send(myMessage);
            }
            catch(ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }

            return;
        }

        //**************************************************
        // Receives a message containing an order.
        //**************************************************
        
        public  void ReceiveMessage()
        {
            // Connect to the a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Set the formatter to indicate body contains an Order.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(MyProject.Order)});
            
            try
            {
                // Receive and format the message.
                Message myMessage =	myQueue.Receive();
                Order myOrder = (Order)myMessage.Body;

                // Display message information.
                Console.WriteLine("Order ID: " +
                    myOrder.orderId.ToString());
                Console.WriteLine("Sent: " +
                    myOrder.orderTime.ToString());
            }
            
            catch (MessageQueueException)
            {
                // Handle Message Queuing exceptions.
            }

                // Handle invalid serialization format.
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
            
            // Catch other exceptions as necessary.

            return;
        }
    }
}
Imports System.Messaging
Imports System.Drawing
Imports System.IO



   
' The following example 
' sends to a queue and receives from a queue.
Public Class Order
      Public orderId As Integer
      Public orderTime As DateTime
End Class

   
  
' Provides a container class for the example.

Public Class MyNewQueue
      
      

   ' Provides an entry point into the application.
   '		 
   ' This example sends and receives a message from
   ' a queue.

   Public Shared Sub Main()
      ' Create a new instance of the class.
      Dim myNewQueue As New MyNewQueue()
        
      ' Create a queue on the local computer.
      CreateQueue(".\myQueue")
         
      ' Send a message to a queue.
      myNewQueue.SendMessage()
       
      ' Receive a message from a queue.
      myNewQueue.ReceiveMessage()
         
      Return
   End Sub
      
      

      ' Creates a new queue.
   Public Shared Sub CreateQueue(queuePath As String)
      Try
         If Not MessageQueue.Exists(queuePath) Then
            MessageQueue.Create(queuePath)
         Else
            Console.WriteLine((queuePath + " already exists."))
         End If
      Catch e As MessageQueueException
         Console.WriteLine(e.Message)
      End Try
   End Sub
       
      

      ' Sends an Order to a queue.

   Public Sub SendMessage()
      Try
            
            ' Create a new order and set values.
            Dim sentOrder As New Order()
            sentOrder.orderId = 3
            sentOrder.orderTime = DateTime.Now
            
            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")
            
            
            
            ' Create the new order.
            Dim myMessage As New Message(sentOrder)
            
            ' Send the order to the queue.
            myQueue.Send(myMessage)
      Catch e As ArgumentException
            Console.WriteLine(e.Message)
      End Try 
         
      Return
   End Sub
      
      
      
 
      ' Receives a message containing an order.
 
   Public Sub ReceiveMessage()
         ' Connect to the a queue on the local computer.
         Dim myQueue As New MessageQueue(".\myQueue")
         
         ' Set the formatter to indicate body contains an Order.
         myQueue.Formatter = New XmlMessageFormatter(New Type() {GetType(Order)})
         
         Try
            ' Receive and format the message. 
            Dim myMessage As Message = myQueue.Receive()
            Dim myOrder As Order = CType(myMessage.Body, Order)
            
            ' Display message information.
            Console.WriteLine(("Order ID: " + myOrder.orderId.ToString()))
            Console.WriteLine(("Sent: " + myOrder.orderTime.ToString()))
         
  
         ' Handle invalid serialization format.
         Catch e As InvalidOperationException
            Console.WriteLine(e.Message)
         End Try
         
         ' Catch other exceptions as necessary.
         Return
   End Sub
End Class

설명

대상 형식 매개 변수가 있는 생성자는 큐에서 읽는 경우에 가장 자주 사용 됩니다. 를 작성할 때 대상 형식을 지정 하는 데 필요한 아닙니다.

이 오버 로드는 XmlMessageFormatter 생성자 집합 합니다 TargetTypeNames 속성을 통해 전달 되는 배열 값을는 targetTypeNames 매개 변수입니다. 설정 하면이 속성을 MessageQueue 이 사용 하 여 XmlMessageFormatter 인스턴스 개체를 포함 하는 메시지를 읽을 수 형식 지정 합니다.

모두를 TargetTypeNamesTargetTypes 속성 알 포맷터는 스키마를 메시지를 역직렬화 하는 동안 일치 시 키 려 합니다. 따라서 메시지 본문을 해석 하는 포맷터입니다.

메시지 본문에 serialize 된 인스턴스는 형식 배열에 있는 스키마 중 하나를 사용 하 여 준수 해야 합니다. 사용 하 여 메시지를 읽을 때의 Receive 메서드를 메서드를 메시지 본문을 읽고 식별 스키마에 해당 하는 형식의 개체를 만듭니다.

두 속성 중 하나만 큐에서 읽을 때 설정 해야 하지만 둘 다 설정할 수 있습니다. 형식 집합이 결합된 된 두 속성 집합입니다. 애플리케이션에는 의사 결정 사용할 것입니다. 메시지 본문 형식 스키마와 일치 하지 않습니다 형식 속성 중 하나에 대 한 배열에 들어 있으면 읽기 시 예외가 throw 됩니다.

적용 대상

XmlMessageFormatter(Type[])

개체 형식의 배열로 전달된 대상 형식을 설정하여 XmlMessageFormatter 클래스의 새 인스턴스를 초기화합니다.

public:
 XmlMessageFormatter(cli::array <Type ^> ^ targetTypes);
public XmlMessageFormatter (Type[] targetTypes);
new System.Messaging.XmlMessageFormatter : Type[] -> System.Messaging.XmlMessageFormatter
Public Sub New (targetTypes As Type())

매개 변수

targetTypes
Type[]

제공된 메시지로부터 포맷터에 의해 역직렬화될 사용 가능한 형식의 집합을 지정하는 Type 형식의 배열입니다.

예외

targetTypes 매개 변수가 null인 경우

설명

대상 형식 매개 변수가 있는 생성자는 큐에서 읽는 경우에 가장 자주 사용 됩니다. 를 작성할 때 대상 형식을 지정 하는 데 필요한 아닙니다.

이 오버 로드는 XmlMessageFormatter 생성자 집합 합니다 TargetTypes 속성을 통해 전달 되는 배열 값을는 targetTypes 매개 변수입니다. 이 속성을 사용 하면 설정을 MessageQueue 이 사용 하 여 XmlMessageFormatter 인스턴스에 지정 된 형식의 개체를 포함 하는 메시지를 읽을 수 있습니다.

모두를 TargetTypeNamesTargetTypes 속성 알 포맷터는 스키마를 메시지를 역직렬화 하는 동안 일치 시 키 려 합니다. 따라서 메시지 본문을 해석 하는 포맷터입니다.

메시지 본문에 serialize 된 인스턴스는 형식 배열에 있는 스키마 중 하나를 사용 하 여 준수 해야 합니다. 사용 하 여 메시지를 읽을 때의 Receive 메서드를 메서드를 메시지 본문을 읽고 식별 스키마에 해당 하는 형식의 개체를 만듭니다.

두 속성 중 하나만 큐에서 읽을 때 설정 해야 하지만 둘 다 설정할 수 있습니다. 형식 집합이 결합된 된 두 속성 집합입니다. 애플리케이션에는 의사 결정 사용할 것입니다. 메시지 본문 형식 스키마와 일치 하지 않습니다 형식 속성 중 하나에 대 한 배열에 들어 있으면 읽기 시 예외가 throw 됩니다.

지정 하는 경우 TargetTypes 대신 TargetTypeNames, 오류가 발생할 가능성이 줄어듭니다 읽기 시간 보다는 컴파일 시간에 형식의 존재 여부 검사 됩니다. TargetTypeNames 정규화 된 어셈블리 이름만 지정 되도록 모든 항목이 필요 합니다. 또한 여러 동시 작업 버전을 사용 하는 경우 버전 번호는 대상 형식 이름에 추가 해야 합니다.

사용 하는 경우 TargetTypes, 각 개체를 추가할 수 있습니다 (예를 들어 MyClass)는 다음 C# 코드에서와 같은 방법으로 목록에 있습니다.

TargetTypes = new Type[]{typeof(MyClass)}  

적용 대상