MessageQueue.Send Metoda

Definice

Odešle objekt do fronty.

Přetížení

Send(Object)

Odešle objekt do neaktuální fronty odkazované tímto MessageQueueobjektem .

Send(Object, MessageQueueTransaction)

Odešle objekt do transakční fronty odkazované tímto MessageQueueobjektem .

Send(Object, MessageQueueTransactionType)

Odešle objekt do fronty odkazované tímto MessageQueueobjektem .

Send(Object, String)

Odešle objekt do neakční fronty, na kterou odkazuje tato MessageQueue fronta, a určuje popisek zprávy.

Send(Object, String, MessageQueueTransaction)

Odešle objekt do transakční fronty, na kterou odkazuje, MessageQueue a určuje popisek zprávy.

Send(Object, String, MessageQueueTransactionType)

Odešle objekt do fronty, na kterou odkazuje, MessageQueue a určuje popisek zprávy.

Send(Object)

Odešle objekt do neaktuální fronty odkazované tímto MessageQueueobjektem .

public:
 void Send(System::Object ^ obj);
public void Send (object obj);
member this.Send : obj -> unit
Public Sub Send (obj As Object)

Parametry

obj
Object

Objekt, který se má odeslat do fronty.

Výjimky

Vlastnost Path nebyla nastavena.

-nebo-

Při přístupu k metodě služby Řízení front zpráv došlo k chybě.

Příklady

Následující příklad kódu se připojí k frontě zpráv a odešle zprávu do fronty.

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

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:
   void SendMessage()
   {
      
      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
      
      // Send a message to the queue.
      if ( myQueue->Transactional == true )
      {
         
         // Create a transaction.
         MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
         
         // Begin the transaction.
         myTransaction->Begin();
         
         // Send the message.
         myQueue->Send( "My Message Data.", myTransaction );
         
         // Commit the transaction.
         myTransaction->Commit();
      }
      else
      {
         myQueue->Send( "My Message Data." );
      }

      return;
   }

};

int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   
   // Send a message to a queue.
   myNewQueue->SendMessage();
   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 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)
            {
                // Create a transaction.
                MessageQueueTransaction myTransaction = new
                    MessageQueueTransaction();

                // Begin the transaction.
                myTransaction.Begin();

                // Send the message.
                myQueue.Send("My Message Data.", myTransaction);

                // Commit the transaction.
                myTransaction.Commit();
            }
            else
            {
                myQueue.Send("My Message Data.");
            }

            return;
        }
    }
}
Imports System.Messaging

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


        '
        ' 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

                ' Create a transaction.
                Dim myTransaction As New MessageQueueTransaction

                ' Begin the transaction.
                myTransaction.Begin()

                ' Send the message.
                myQueue.Send("My Message Data.", myTransaction)

                ' Commit the transaction.
                myTransaction.Commit()

            Else
                myQueue.Send("My Message Data.")
            End If

            Return

        End Sub

End Class

Následující příklad kódu odešle třídu definovanou Order aplikací do fronty a pak z této fronty obdrží zprávu.

Poznámky

Toto přetížení použijte k odeslání zprávy obsahující obj parametr do fronty, na kterou MessageQueueodkazuje . Objekt, který odešlete do fronty, může být spravovaný Message objekt nebo jakýkoliv. Pokud odešlete jiný objekt než Messageobjekt , je objekt serializován a vložen do textu zprávy.

Pokud toto přetížení použijete k odeslání zprávy do transakční fronty, zpráva se odešle do fronty nedoručených zpráv. Pokud chcete, aby zpráva byla součástí transakce, která obsahuje jiné zprávy, použijte přetížení, které přebírá MessageQueueTransaction nebo MessageQueueTransactionType jako parametr.

Pokud před voláním FormatterSend(Object)nenastavíte vlastnost , formátovací modul ve výchozím nastavení nastaví hodnotu XmlMessageFormatter.

Vlastnost DefaultPropertiesToSend platí pro jakýkoli jiný objekt než Messageobjekt . Pokud například pomocí člena zadáte popisek nebo prioritu DefaultPropertiesToSend , budou tyto hodnoty platit pro všechny zprávy obsahující objekt, který není typu Message , když ho aplikace odešle do fronty. Při odesílání Messagemají hodnoty vlastnosti nastavené pro Message přednost před DefaultPropertiesToSend a vlastnost zprávy Message.Formatter má přednost před vlastností fronty MessageQueue.Formatter .

Následující tabulka ukazuje, zda je tato metoda k dispozici v různých režimech pracovní skupiny.

Režim pracovní skupiny K dispozici.
Místní počítač Yes
Název místního počítače a přímého formátu Yes
Vzdálený počítač No
Název vzdáleného počítače a přímého formátu Yes

Viz také

Platí pro

Send(Object, MessageQueueTransaction)

Odešle objekt do transakční fronty odkazované tímto MessageQueueobjektem .

public:
 void Send(System::Object ^ obj, System::Messaging::MessageQueueTransaction ^ transaction);
public void Send (object obj, System.Messaging.MessageQueueTransaction transaction);
member this.Send : obj * System.Messaging.MessageQueueTransaction -> unit
Public Sub Send (obj As Object, transaction As MessageQueueTransaction)

Parametry

obj
Object

Objekt, který se má odeslat do fronty.

Výjimky

Parametr transaction je null.

Vlastnost Path nebyla nastavena.

-nebo-

Aplikace Řízení front zpráv označila nesprávné použití transakce.

-nebo-

Při přístupu k metodě služby Řízení front zpráv došlo k chybě.

Příklady

Následující příklad kódu odešle řetězec do transakční fronty a pak obdrží zprávu z této fronty.

#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
{
public:

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

      // Send a message to the queue.
      if ( myQueue->Transactional == true )
      {
         // Create a transaction.
         MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;

         // Begin the transaction.
         myTransaction->Begin();

         // Send the message.
         myQueue->Send( "My Message Data.", myTransaction );

         // Commit the transaction.
         myTransaction->Commit();
      }

      return;
   }


   //*************************************************
   // Receives a message containing an Order.
   //*************************************************
   void ReceiveMessageTransactional()
   {
      // Connect to a transactional queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );

      // Set the formatter.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = String::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );

      // Create a transaction.
      MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
      try
      {
         // Begin the transaction.
         myTransaction->Begin();

         // Receive the message. 
         Message^ myMessage = myQueue->Receive( myTransaction );
         String^ myOrder = static_cast<String^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( myOrder );

         // Commit the transaction.
         myTransaction->Commit();
      }
      catch ( MessageQueueException^ e ) 
      {
         // Handle nontransactional queues.
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::TransactionUsage )
         {
            Console::WriteLine( "Queue is not transactional." );
         }

         // Else catch other sources of MessageQueueException.
         // Roll back the transaction.
         myTransaction->Abort();
      }

      // Catch other exceptions as necessary, such as 
      // InvalidOperationException, thrown when the formatter 
      // cannot deserialize the message.
      return;
   }
};

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

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

   // Receive a message from a queue.
   myNewQueue->ReceiveMessageTransactional();
   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 transactional queue.
        //**************************************************

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

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

            // Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional();
        
            return;
        }

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

            // Send a message to the queue.
            if (myQueue.Transactional == true)
            {
                // Create a transaction.
                MessageQueueTransaction myTransaction = new
                    MessageQueueTransaction();

                // Begin the transaction.
                myTransaction.Begin();

                // Send the message.
                myQueue.Send("My Message Data.", myTransaction);

                // Commit the transaction.
                myTransaction.Commit();
            }

            return;
        }

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

            // Set the formatter.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(String)});
            
            // Create a transaction.
            MessageQueueTransaction myTransaction = new
                MessageQueueTransaction();

            try
            {
                // Begin the transaction.
                myTransaction.Begin();
                
                // Receive the message.
                Message myMessage =	myQueue.Receive(myTransaction);
                String myOrder = (String)myMessage.Body;

                // Display message information.
                Console.WriteLine(myOrder);

                // Commit the transaction.
                myTransaction.Commit();
            }
            
            catch (MessageQueueException e)
            {
                // Handle nontransactional queues.
                if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.TransactionUsage)
                {
                    Console.WriteLine("Queue is not transactional.");
                }
                
                // Else catch other sources of MessageQueueException.

                // Roll back the transaction.
                myTransaction.Abort();
            }

            // Catch other exceptions as necessary, such as
            // InvalidOperationException, thrown when the formatter
            // cannot deserialize the message.

            return;
        }
    }
}
Imports System.Messaging

   
Public Class MyNewQueue


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

        Public Shared Sub Main()

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

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

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional()

            Return

        End Sub


        '
        ' Sends a message to a queue.
        '

        Public Sub SendMessageTransactional()

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

            ' Send a message to the queue.
            If myQueue.Transactional = True Then
                ' Create a transaction.
                Dim myTransaction As New MessageQueueTransaction

                ' Begin the transaction.
                myTransaction.Begin()

                ' Send the message.
                myQueue.Send("My Message Data.", myTransaction)

                ' Commit the transaction.
                myTransaction.Commit()
            End If

            Return

        End Sub


        '
        ' Receives a message containing an Order.
        '

        Public Sub ReceiveMessageTransactional()

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

            ' Set the formatter.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType([String])})

            ' Create a transaction.
            Dim myTransaction As New MessageQueueTransaction

            Try

                ' Begin the transaction.
                myTransaction.Begin()

                ' Receive the message. 
                Dim myMessage As Message = _
                    myQueue.Receive(myTransaction)
                Dim myOrder As [String] = CType(myMessage.Body, _
                    [String])

                ' Display message information.
                Console.WriteLine(myOrder)

                ' Commit the transaction.
                myTransaction.Commit()


            Catch e As MessageQueueException

                ' Handle nontransactional queues.
                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.TransactionUsage Then

                    Console.WriteLine("Queue is not transactional.")

                End If

                ' Else catch other sources of a MessageQueueException.


                ' Roll back the transaction.
                myTransaction.Abort()


                ' Catch other exceptions as necessary, such as 
                ' InvalidOperationException, thrown when the formatter
                ' cannot deserialize the message.

            End Try

            Return

        End Sub

End Class

Poznámky

Toto přetížení použijte k odeslání zprávy, která obsahuje obj parametr do transakční fronty odkazované objektem MessageQueue, pomocí kontextu interní transakce definované parametrem transaction . Objekt, který odešlete do fronty, může být spravovaný Message objekt nebo jakýkoliv. Pokud odešlete jiný objekt než Messageobjekt , je objekt serializován a vložen do textu zprávy.

Pokud toto přetížení použijete k odeslání zprávy do neaktuální fronty, může být zpráva odeslána do fronty nedoručených zpráv bez vyvolání výjimky.

Pokud před voláním FormatterSend(Object)nenastavíte vlastnost , formátovací modul ve výchozím nastavení nastaví hodnotu XmlMessageFormatter.

Vlastnost DefaultPropertiesToSend platí pro jakýkoli jiný objekt než Messageobjekt . Pokud například pomocí člena zadáte popisek nebo prioritu DefaultPropertiesToSend , budou tyto hodnoty platit pro všechny zprávy obsahující objekt, který není typu Message , když ho aplikace odešle do fronty. Při odesílání Messagemají hodnoty vlastnosti nastavené pro Message přednost před DefaultPropertiesToSend a vlastnost zprávy Message.Formatter má přednost před vlastností fronty MessageQueue.Formatter .

MessageQueueTransaction je s vlákny apartment aware, takže pokud je STAstav vašeho bytu , nemůžete použít transakci ve více vláknech. Visual Basic nastaví stav hlavního vlákna na STA, takže musíte použít MTAThreadAttribute v podprogramu Main . V opačném případě odeslání transakční zprávy pomocí jiného vlákna vyvolá MessageQueueException výjimku. Použijete ho MTAThreadAttribute pomocí následujícího fragmentu.

<System.MTAThreadAttribute>
 public sub Main()

Následující tabulka ukazuje, zda je tato metoda k dispozici v různých režimech pracovní skupiny.

Režim pracovní skupiny K dispozici.
Místní počítač Yes
Název místního počítače a přímého formátu Yes
Vzdálený počítač No
Název vzdáleného počítače a přímého formátu Yes

Viz také

Platí pro

Send(Object, MessageQueueTransactionType)

Odešle objekt do fronty odkazované tímto MessageQueueobjektem .

public:
 void Send(System::Object ^ obj, System::Messaging::MessageQueueTransactionType transactionType);
public void Send (object obj, System.Messaging.MessageQueueTransactionType transactionType);
member this.Send : obj * System.Messaging.MessageQueueTransactionType -> unit
Public Sub Send (obj As Object, transactionType As MessageQueueTransactionType)

Parametry

obj
Object

Objekt, který se má odeslat do fronty.

transactionType
MessageQueueTransactionType

Jedna z MessageQueueTransactionType hodnot popisující typ kontextu transakce, který se má přidružit ke zprávě.

Výjimky

Parametr transactionType není jedním ze MessageQueueTransactionType členů.

Vlastnost Path nebyla nastavena.

-nebo-

Při přístupu k metodě služby Řízení front zpráv došlo k chybě.

Příklady

Následující příklad kódu ukazuje použití .Send(Object, MessageQueueTransactionType)


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

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, MessageQueueTransactionType::Single);

queue->Close();

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

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, MessageQueueTransactionType.Single);

Poznámky

Toto přetížení použijte k odeslání zprávy, která obsahuje obj parametr do fronty odkazované objektem MessageQueue, pomocí kontextu transakce definovaného parametrem transactionType . transactionType Jako parametr zadejteAutomatic, pokud je již k vláknu připojen kontext externí transakce, který chcete použít k odeslání zprávy. Určete Single , jestli chcete zprávu odeslat jako jednu interní transakci. Můžete určit None , jestli chcete odeslat transakční zprávu do neakčního vlákna.

Objekt, který odešlete do fronty, může být spravovaný Message objekt nebo jakýkoliv. Pokud odešlete jiný objekt než Messageobjekt , je objekt serializován a vložen do textu zprávy.

Pokud před voláním FormatterSend(Object)nenastavíte vlastnost , formátovací modul ve výchozím nastavení nastaví hodnotu XmlMessageFormatter.

Vlastnost DefaultPropertiesToSend platí pro jakýkoli jiný objekt než Messageobjekt . Pokud například pomocí člena zadáte popisek nebo prioritu DefaultPropertiesToSend , budou tyto hodnoty platit pro všechny zprávy obsahující objekt, který není typu Message , když ho aplikace odešle do fronty. Při odesílání Messagemají hodnoty vlastnosti nastavené pro Message přednost před DefaultPropertiesToSend a vlastnost zprávy Message.Formatter má přednost před vlastností fronty MessageQueue.Formatter .

Následující tabulka ukazuje, zda je tato metoda k dispozici v různých režimech pracovní skupiny.

Režim pracovní skupiny K dispozici.
Místní počítač Yes
Název místního počítače a přímého formátu Yes
Vzdálený počítač No
Název vzdáleného počítače a přímého formátu Yes

Viz také

Platí pro

Send(Object, String)

Odešle objekt do neakční fronty, na kterou odkazuje tato MessageQueue fronta, a určuje popisek zprávy.

public:
 void Send(System::Object ^ obj, System::String ^ label);
public void Send (object obj, string label);
member this.Send : obj * string -> unit
Public Sub Send (obj As Object, label As String)

Parametry

obj
Object

Objekt, který se má odeslat do fronty.

label
String

Popisek zprávy.

Výjimky

Parametr label je null.

Vlastnost Path nebyla nastavena.

-nebo-

Při přístupu k metodě služby Řízení front zpráv došlo k chybě.

Příklady

Následující příklad kódu ukazuje použití .Send(Object, String)


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

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, "Example Message Label");

queue->Close();

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

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, "Example Message Label");

Poznámky

Toto přetížení použijte k odeslání zprávy obsahující obj parametr do fronty, na kterou MessageQueueodkazuje . S tímto přetížením můžete zadat popisek řetězce, který identifikuje zprávu. Objekt, který odešlete do fronty, může být Message, struktura, datový objekt nebo jakýkoli spravovaný objekt. Pokud odešlete jiný objekt než Messageobjekt , je objekt serializován a vložen do textu zprávy.

Popisek zprávy se liší od popisku fronty zpráv, ale oba jsou závislé na aplikaci a nemají žádný zděděný význam pro službu Řízení front zpráv.

Pokud toto přetížení použijete k odeslání zprávy do transakční fronty, zpráva se odešle do fronty nedoručených zpráv. Pokud chcete, aby zpráva byla součástí transakce, která obsahuje jiné zprávy, použijte přetížení, které přebírá MessageQueueTransaction nebo MessageQueueTransactionType jako parametr.

Vlastnost Path pro tuto MessageQueue instanci musí být zadána před odesláním zprávy. Pokud před voláním FormatterSend(Object)nenastavíte vlastnost , formátovací modul ve výchozím nastavení nastaví hodnotu XmlMessageFormatter.

Vlastnost DefaultPropertiesToSend platí pro jakýkoli jiný objekt než Messageobjekt . Pokud například pomocí člena zadáte popisek nebo prioritu DefaultPropertiesToSend , budou tyto hodnoty platit pro všechny zprávy obsahující objekt, který není typu Message , když ho aplikace odešle do fronty. Při odesílání Messagemají hodnoty vlastnosti nastavené pro Message přednost před DefaultPropertiesToSend a vlastnost zprávy Message.Formatter má přednost před vlastností fronty MessageQueue.Formatter .

Následující tabulka ukazuje, zda je tato metoda k dispozici v různých režimech pracovní skupiny.

Režim pracovní skupiny K dispozici.
Místní počítač Yes
Název místního počítače a přímého formátu Yes
Vzdálený počítač No
Název vzdáleného počítače a přímého formátu Yes

Viz také

Platí pro

Send(Object, String, MessageQueueTransaction)

Odešle objekt do transakční fronty, na kterou odkazuje, MessageQueue a určuje popisek zprávy.

public:
 void Send(System::Object ^ obj, System::String ^ label, System::Messaging::MessageQueueTransaction ^ transaction);
public void Send (object obj, string label, System.Messaging.MessageQueueTransaction transaction);
member this.Send : obj * string * System.Messaging.MessageQueueTransaction -> unit
Public Sub Send (obj As Object, label As String, transaction As MessageQueueTransaction)

Parametry

obj
Object

Objekt, který se má odeslat do fronty.

label
String

Popisek zprávy.

Výjimky

Parametr label je null.

-nebo-

Parametr transaction je null.

Vlastnost Path nebyla nastavena.

-nebo-

Aplikace Řízení front zpráv označila nesprávné využití transakcí.

-nebo-

Při přístupu k metodě služby Řízení front zpráv došlo k chybě.

Příklady

Následující příklad kódu ukazuje použití .Send(Object, String, MessageQueueTransaction)


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

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Create a message queuing transaction.
MessageQueueTransaction^ transaction = gcnew MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction->Begin();

    // Send the message to the queue.
    queue->Send(msg, "Example Message Label", transaction);

    // Commit the transaction.
    transaction->Commit();
}
catch (Exception^ ex)
{
    // Cancel the transaction.
    transaction->Abort();

    // Propagate the exception.
    throw ex;
}
finally
{
    // Dispose of the transaction object.
    delete transaction;
    queue->Close();
}

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

// Create a new message.
Message msg = new Message("Example Message Body");

// Create a message queuing transaction.
MessageQueueTransaction transaction = new MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction.Begin();

    // Send the message to the queue.
    queue.Send(msg, "Example Message Label", transaction);

    // Commit the transaction.
    transaction.Commit();
}
catch(System.Exception e)
{
    // Cancel the transaction.
    transaction.Abort();

    // Propagate the exception.
    throw e;
}
finally
{
    // Dispose of the transaction object.
    transaction.Dispose();
}

Poznámky

Toto přetížení použijte k odeslání zprávy, která obsahuje obj parametr do transakční fronty odkazované objektem MessageQueue, pomocí kontextu interní transakce definované parametrem transaction . S tímto přetížením můžete zadat popisek řetězce, který identifikuje zprávu. Objekt, který odešlete do fronty, může být Message, struktura, datový objekt nebo jakýkoli spravovaný objekt. Pokud odešlete jiný objekt než Messageobjekt , je objekt serializován a vložen do textu zprávy.

Popisek zprávy se liší od popisku fronty zpráv, ale oba jsou závislé na aplikaci a nemají žádný zděděný význam pro službu Řízení front zpráv.

Pokud toto přetížení použijete k odeslání zprávy do neaktuální fronty, může být zpráva odeslána do fronty nedoručených zpráv bez vyvolání výjimky.

Pokud před voláním FormatterSend(Object)nenastavíte vlastnost , formátovací modul ve výchozím nastavení nastaví hodnotu XmlMessageFormatter.

Vlastnost DefaultPropertiesToSend platí pro jakýkoli jiný objekt než Messageobjekt . Pokud například pomocí člena zadáte popisek nebo prioritu DefaultPropertiesToSend , budou tyto hodnoty platit pro všechny zprávy obsahující objekt, který není typu Message , když ho aplikace odešle do fronty. Při odesílání Messagemají přednost hodnoty vlastnosti nastavené pro Message přednost před DefaultPropertiesToSend a vlastnost zprávy Message.Formatter má přednost před vlastností fronty MessageQueue.Formatter .

MessageQueueTransaction je s vlákny apartment aware, takže pokud je STAstav vašeho bytu , nemůžete použít transakci ve více vláknech. Visual Basic nastaví stav hlavního vlákna na STA, takže musíte použít MTAThreadAttribute v podprogramu Main . V opačném případě odeslání transakční zprávy pomocí jiného vlákna vyvolá MessageQueueException výjimku. Použijete ho MTAThreadAttribute pomocí následujícího fragmentu.

<System.MTAThreadAttribute>
 public sub Main()

Následující tabulka ukazuje, zda je tato metoda k dispozici v různých režimech pracovní skupiny.

Režim pracovní skupiny K dispozici.
Místní počítač Yes
Název místního počítače a přímého formátu Yes
Vzdálený počítač No
Název vzdáleného počítače a přímého formátu Yes

Viz také

Platí pro

Send(Object, String, MessageQueueTransactionType)

Odešle objekt do fronty, na kterou se odkazuje, MessageQueue a určí popisek zprávy.

public:
 void Send(System::Object ^ obj, System::String ^ label, System::Messaging::MessageQueueTransactionType transactionType);
public void Send (object obj, string label, System.Messaging.MessageQueueTransactionType transactionType);
member this.Send : obj * string * System.Messaging.MessageQueueTransactionType -> unit
Public Sub Send (obj As Object, label As String, transactionType As MessageQueueTransactionType)

Parametry

obj
Object

Objekt, který se má odeslat do fronty.

label
String

Popisek zprávy.

transactionType
MessageQueueTransactionType

Jedna z MessageQueueTransactionType hodnot popisující typ kontextu transakce, který se má přidružit ke zprávě.

Výjimky

Parametr label je null.

Aplikace Řízení front zpráv označila nesprávné využití transakcí.

Parametr transactionType není jedním ze MessageQueueTransactionType členů.

Vlastnost Path nebyla nastavena.

-nebo-

Při přístupu k metodě služby Řízení front zpráv došlo k chybě.

Příklady

Následující příklad kódu ukazuje použití .Send(Object, String, MessageQueueTransactionType)


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

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, "Example Message Label",
    MessageQueueTransactionType::Single);

queue->Close();

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

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, "Example Message Label",
    MessageQueueTransactionType.Single);

Poznámky

Toto přetížení použijte k odeslání zprávy, která obsahuje obj parametr do fronty odkazované objektem MessageQueue, pomocí kontextu transakce definovaného parametrem transactionType . transactionType Jako parametr zadejteAutomatic, pokud je již k vláknu připojen kontext externí transakce, který chcete použít k odeslání zprávy. Určete Single , jestli chcete zprávu odeslat jako jednu interní transakci. Můžete určit None , jestli chcete odeslat transakční zprávu do neakčního vlákna.

Objekt, který odešlete do fronty, může být spravovaný Message objekt nebo jakýkoliv. Pokud odešlete jiný objekt než Messageobjekt , je objekt serializován a vložen do textu zprávy. S tímto přetížením můžete zadat popisek řetězce, který identifikuje zprávu.

Popisek zprávy se liší od popisku fronty zpráv, ale oba jsou závislé na aplikaci a nemají žádný zděděný význam pro službu Řízení front zpráv.

Pokud před voláním FormatterSend(Object)nenastavíte vlastnost , formátovací modul ve výchozím nastavení nastaví hodnotu XmlMessageFormatter.

Vlastnost DefaultPropertiesToSend platí pro jakýkoli jiný objekt než Messageobjekt . Pokud například pomocí člena zadáte popisek nebo prioritu DefaultPropertiesToSend , budou tyto hodnoty platit pro všechny zprávy obsahující objekt, který není typu Message , když ho aplikace odešle do fronty. Při odesílání Messagemají hodnoty vlastnosti nastavené pro Message přednost před DefaultPropertiesToSenda vlastnost zprávy Message.Formatter má přednost před vlastností fronty MessageQueue.Formatter .

Následující tabulka ukazuje, zda je tato metoda k dispozici v různých režimech pracovní skupiny.

Režim pracovní skupiny K dispozici.
Místní počítač Yes
Název místního počítače a přímého formátu Yes
Vzdálený počítač No
Název vzdáleného počítače a přímého formátu Yes

Viz také

Platí pro