Export (0) Print
Expand All

MessageQueue.Send Method (Object)

.NET Framework 1.1

Sends an object to nontransactional queue referenced by this MessageQueue.

[Visual Basic]
Overloads Public Sub Send( _
   ByVal obj As Object _
)
[C#]
public void Send(
 object obj
);
[C++]
public: void Send(
 Object* obj
);
[JScript]
public function Send(
   obj : Object
);

Parameters

obj
The object to send to the queue.

Exceptions

Exception Type Condition
MessageQueueException The Path property has not been set.

-or-

An error occurred when accessing a Message Queuing API.

Remarks

Use this overload to send a message containing the obj parameter to the queue referenced by the MessageQueue. The object you send to the queue can be a Message or any managed object. If you send any object other than a Message, the object is serialized and inserted into the body of the message.

If you use this overload to send a message to a transactional queue, the message will be sent to the dead-letter queue. If you want the message to be part of a transaction that contains other messages, use an overload that takes a MessageQueueTransaction or MessageQueueTransactionType as a parameter.

If you do not set the Formatter property before calling Send, the formatter defaults to the XmlMessageFormatter.

The DefaultPropertiesToSend property applies to any object other than a Message. If you specify, for example, a label or a priority using the DefaultPropertiesToSend member, these values apply to any message that contains an object that is not of type Message when your application sends it to the queue. When sending a Message, the property values set for the Message take precedence over DefaultPropertiesToSend, and the message's Message.Formatter property takes precedence over the queue's MessageQueue.Formatter property.

The following table shows whether this method is available in various Workgroup modes.

Workgroup Mode Available
Local computer Yes
Local computer + direct format name Yes
Remote computer No
Remote computer + direct format name Yes

Example

[Visual Basic, C#, C++] The following example connects to a message queue and sends a message to the queue.

[Visual Basic] 
Imports System
Imports 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 a message to a queue.
        '**************************************************

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Send a message to a queue.
            myNewQueue.SendMessage()

            Return

        End Sub 'Main


        '**************************************************
        ' Sends a message to a queue.
        '**************************************************

        Public Sub SendMessage()

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Send a message to the queue.
            If myQueue.Transactional = True Then
                myQueue.Send("My Message Data.", New _
                    MessageQueueTransaction())
            Else
                myQueue.Send("My Message Data.")
            End If

            Return

        End Sub 'SendMessage

    End Class 'MyNewQueue
End Namespace 'MyProject

[C#] 
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 a message to a queue.
        //**************************************************

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

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

            return;
        }


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

            // Send a message to the queue.
            if (myQueue.Transactional == true)
            {
                myQueue.Send("My Message Data.", new 
                    MessageQueueTransaction());
            }
            else
            {
                myQueue.Send("My Message Data.");
            }

            return;
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>
#using <system.messaging.dll.>

using namespace System;
using namespace System::Messaging;

__gc class MyNewQueue 
{
public:
    void SendMessage() 
    {

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

        // Send a message to the queue.
        if (myQueue->Transactional == true) 
        {
            myQueue->Send(S"My Message Data.", new 
                MessageQueueTransaction());
        }
        else 
        {
            myQueue->Send(S"My Message Data.");
        }

        return;
    }
};

int main() 
{
    // Create a new instance of the class.
    MyNewQueue* myNewQueue = new MyNewQueue();
    // Send a message to a queue.
    myNewQueue->SendMessage();

    return 0;
}

[Visual Basic, C#, C++] The following example sends an application-defined Order class to a queue and then receives a message from that queue.

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue.Send Overload List | DefaultPropertiesToSend | Message | Path | Peek | Receive | BeginPeek | BeginReceive

Show:
© 2014 Microsoft