<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Enviar y recibir mensajes mediante programación</Title>
      <Author>Microsoft Corporation</Author>
      <Description>Envía un mensaje a una cola en el equipo local, recibe el mensaje y da formato al cuerpo como una cadena.</Description>
      <Shortcut>mqSendRec</Shortcut>
    </Header>
    <Snippet>
      <References>
        <Reference>
          <Assembly>System.Messaging.dll</Assembly>
          <Url/>
        </Reference>
      </References>
      <Imports>
        <Import>
          <Namespace>System</Namespace>
        </Import>
        <Import>
          <Namespace>Microsoft.VisualBasic</Namespace>
        </Import>
        <Import>
          <Namespace>System.Messaging</Namespace>
        </Import>
      </Imports>
      <Declarations>
        <Literal>
          <ID>QueueName</ID>
          <Type>String</Type>
          <ToolTip>Reemplazar por el nombre de cola. "." representa el equipo local.</ToolTip>
          <Default>".\QueueName"</Default>
        </Literal>
        <Literal>
          <ID>Message</ID>
          <Type>String</Type>
          <ToolTip>Reemplazar por el mensaje. El mensaje puede ser cualquier tipo de objeto.</ToolTip>
          <Default>"Message text"</Default>
        </Literal>
        <Literal>
          <ID>BodyType</ID>
          <Type>System.Type</Type>
          <ToolTip>Reemplazar por el tipo del mensaje. Debe coincidir con el tipo del objeto enviado en el comando Enviar.</ToolTip>
          <Default>GetType(String)</Default>
        </Literal>
      </Declarations>
      <Code Language="VB" Kind="method body"><![CDATA[Dim queue As New System.Messaging.MessageQueue($QueueName$)

' Send a message to the queue.
queue.Send($Message$)

' Wait for the message to arrive, and then remove
' it from the queue.
Dim msg As Message
msg = queue.Receive(New TimeSpan(0, 0, 3))

' Convert the body to a string.
msg.Formatter = New XmlMessageFormatter(New Type() {$BodyType$})
Dim text As String = msg.Body.ToString]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
