Message.Body 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
메시지의 내용을 가져오거나 설정합니다.
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
속성 값
메시지 내용을 지정하는 개체입니다. 개체는 문자열, 날짜, 통화, 숫자, 바이트 배열 또는 관리되는 개체일 수 있습니다.
- 특성
예외
예제
다음 코드 예제에서는 서로 다른 우선 순위의 두 메시지를 큐에 보내고 이후에 검색합니다.
#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 속성은 일반적으로 메시지와 연결된 데이터를 포함합니다. 애플리케이션 관련 데이터를 및 Extension 속성에 AppSpecific 보낼 수도 있지만 가능하면 메시지의 메시지 데이터를 Body 포함해야 합니다. Body 속성 내용만 직렬화되거나 암호화됩니다.
이 속성은 Body 크기가 4MB를 초과하지 않는 모든 개체를 포함할 수 있습니다. 형식 MessageQueueMessage 이 아닌 개체를 보내는 데 사용하는 MessageQueue.Send 경우 해당 개체는 반환되거나 반환된 ReceivePeek 인스턴스의 Message 속성에 Body 있습니다.
문자열 인수 MessageQueue.Send("hello.") 는 이러한 제네릭 개체의 예입니다.
이 속성은 BodyType 메시지 본문에 저장된 정보의 형식을 나타냅니다. 메시지 큐는 이 정보를 사용하여 속성 콘텐츠의 형식을 Body 식별합니다.
개체를 Body 보내기 전에 속성 또는 BodyStream 속성을 지정합니다 Message . 속성은 Body 텍스트 문자열, 구조체 개체, 클래스 인스턴스 또는 포함된 개체와 같은 직렬화 가능한 개체일 수 있습니다.
메시지 내용을 속성에 직접 BodyStream 쓰지 않는 한 메시지를 보내기 전에 속성을 설정합니다 Formatter . 인스턴스에서 Send 메서드가 MessageQueue 호출되면 본문은 속성에 포함된 포맷터를 사용하여 직렬화됩니다 Formatter . 속성 값을 지정 Formatter 하지 않고 메시지를 보내는 경우 포맷터는 기본적으로 .로 설정 XmlMessageFormatter됩니다.
메모
메시지 MaxValue 본문을 설정하려고 하면 클래스의 MessageQueue 메서드가 OverflowException 호출되고 ActiveXMessageFormatter 사용될 때 Send 발생합니다.