Message.Body 속성

정의

메시지의 내용을 가져오거나 설정합니다.

public:
 property System::Object ^ Body { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Browsable(false)]
public object Body { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Body : obj with get, set
Public Property Body As Object

속성 값

메시지 내용을 지정하는 개체입니다. 개체는 문자열, 날짜, 통화, 숫자, 바이트 배열 또는 관리되는 개체 등이 될 수 있습니다.

특성

예외

Formatter 속성은 null입니다.

또는

메시지 큐가 Body 속성을 무시하도록 필터링된 경우

예제

다음 코드 예제에서는 큐에 다른 우선 순위 2 메시지를 보내고 이후에 검색 합니다.


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

using namespace System;
using namespace System::Messaging;

/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
   //**************************************************
   // Sends a string message to a queue.
   //**************************************************
public:
   void SendMessage( MessagePriority priority, String^ messageBody )
   {
      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Create a new message.
      Message^ myMessage = gcnew Message;
      if ( priority > MessagePriority::Normal )
      {
         myMessage->Body = "High Priority: {0}",messageBody;
      }
      else
      {
         myMessage->Body = messageBody;
      }

      // Set the priority of the message.
      myMessage->Priority = priority;

      // Send the Order to the queue.
      myQueue->Send( myMessage );

      return;
   }

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

      // Set the queue to read the priority. By default, it
      // is not read.
      myQueue->MessageReadPropertyFilter->Priority = true;

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

         // Display message information.
         Console::WriteLine( "Priority: {0}",
            myMessage->Priority );
         Console::WriteLine( "Body: {0}",
            myMessage->Body );
      }
      catch ( MessageQueueException^ ) 
      {
         // Handle Message Queuing exceptions.
      }
      // Handle invalid serialization format.
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

      // Catch other exceptions as necessary.

      return;
   }
};

//**************************************************
// Provides an entry point into the application.
//		 
// This example sends and receives a message from
// a queue.
//**************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Send messages to a queue.
   myNewQueue->SendMessage( MessagePriority::Normal, "First Message Body." );
   myNewQueue->SendMessage( MessagePriority::Highest, "Second Message Body." );

   // Receive messages from a queue.
   myNewQueue->ReceiveMessage();
   myNewQueue->ReceiveMessage();

   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

    /// <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();

            // Send messages to a queue.
            myNewQueue.SendMessage(MessagePriority.Normal, "First Message Body.");
            myNewQueue.SendMessage(MessagePriority.Highest, "Second Message Body.");

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

            return;
        }

        //**************************************************
        // Sends a string message to a queue.
        //**************************************************
        
        public void SendMessage(MessagePriority priority, string messageBody)
        {

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

            // Create a new message.
            Message myMessage = new Message();

            if(priority > MessagePriority.Normal)
            {
                myMessage.Body = "High Priority: " + messageBody;
            }
            else
            {
                myMessage.Body = messageBody;
            }

            // Set the priority of the message.
            myMessage.Priority = priority;

            // Send the Order to the queue.
            myQueue.Send(myMessage);

            return;
        }

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

            // Set the queue to read the priority. By default, it
            // is not read.
            myQueue.MessageReadPropertyFilter.Priority = true;

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

                // Display message information.
                Console.WriteLine("Priority: " +
                    myMessage.Priority.ToString());
                Console.WriteLine("Body: " +
                    myMessage.Body.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


'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()
         
         ' Send messages to a queue.
         myNewQueue.SendMessage(MessagePriority.Normal, "First Message Body.")
         myNewQueue.SendMessage(MessagePriority.Highest, "Second Message Body.")
         
         ' Receive messages from a queue.
         myNewQueue.ReceiveMessage()
         myNewQueue.ReceiveMessage()
         
         Return
      End Sub
      
      
      

      ' Sends a string message to a queue.

      Public Sub SendMessage(priority As MessagePriority, messageBody As String)
         
         ' Connect to a queue on the local computer.
         Dim myQueue As New MessageQueue(".\myQueue")
         
         ' Create a new message.
         Dim myMessage As New Message()
         
         If priority > MessagePriority.Normal Then
            myMessage.Body = "High Priority: " + messageBody
         Else
            myMessage.Body = messageBody
         End If 
         ' Set the priority of the message.
         myMessage.Priority = priority
         
         
         ' Send the Order to the queue.
         myQueue.Send(myMessage)
         
         Return
      End Sub
      
      
      

      ' Receives a message.

      Public Sub ReceiveMessage()
         ' Connect to the a queue on the local computer.
         Dim myQueue As New MessageQueue(".\myQueue")
         
         ' Set the queue to read the priority. By default, it
         ' is not read.
         myQueue.MessageReadPropertyFilter.Priority = True
         
         ' Set the formatter to indicate body contains a string.
         myQueue.Formatter = New XmlMessageFormatter(New Type() {GetType(String)})
         
         Try
            ' Receive and format the message. 
            Dim myMessage As Message = myQueue.Receive()
            
            ' Display message information.
            Console.WriteLine(("Priority: " + myMessage.Priority.ToString()))
            Console.WriteLine(("Body: " + myMessage.Body.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

설명

메시지의 Body 속성은 일반적으로 메시지를 사용 하 여 관련 데이터를 포함 합니다. 애플리케이션별 데이터를 보낼 수도 있습니다 하지만 AppSpecificExtension 속성을 메시지 데이터를 포함 해야는 Body 가능할 때마다 메시지의 합니다. 만 Body 속성 내용을 serialize 되거나 암호화 됩니다.

Body 속성 크기가 4MB를 넘지 않는 개체를 포함할 수 있습니다. 사용 하는 경우 MessageQueue.Send 형식이 아닌 개체를 보낼 MessageMessageQueue, 해당 개체에 배치 됩니다는 Body 속성을 Message 에서 반환한 인스턴스 Peek 또는 Receive.

문자열 인수 MessageQueue.Send("hello.") 은 예제는 이러한 일반 개체입니다.

BodyType 속성 유형의 메시지 본문에 저장 된 정보를 나타냅니다. 메시지 큐의 형식을 식별 하기 위해이 정보를 사용 합니다 Body 속성 내용입니다.

지정 된 Body 속성 또는 BodyStream 보내기 전에 속성을 Message 개체입니다. Body 속성은 모든 텍스트 문자열 같은 직렬화 가능 개체, 구조체, 클래스 인스턴스 또는 포함 된 개체 수 있습니다.

메시지의 콘텐츠를 직접 작성 하지 않는 경우는 BodyStream 속성을 설정 합니다 Formatter 메시지를 보내기 전에 속성입니다. 경우는 Send 메서드를 호출 합니다 MessageQueue 인스턴스를 본문에 포함 된 포맷터를 사용 하 여 serialize 되는 Formatter 속성. 에 대 한 값을 지정 하지 않고 메시지를 보내기 합니다 Formatter 속성을 포맷터의 기본값은 XmlMessageFormatter합니다.

참고

메시지의 본문을 설정 하려고 MaxValue 하면를 OverflowException 때를 Send 메서드를 MessageQueue 클래스 라고 및 ActiveXMessageFormatter 사용 됩니다.

적용 대상

추가 정보