AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Receive a message from a message queue?



Message queuing makes it easy for application developers to communicate with application programs quickly and reliably by sending and receiving messages. Messaging provides you with guaranteed message delivery and a robust, fail-safe way to carry out many of your business processes.

The MessageQueue component allows you to easily incorporate message-based communication into your applications. Using this component and its associated language features, you can send and receive messages, explore existing queues, create and delete queues, and perform a variety of other operations using a simple programming model.

The sample illustrates how to use the MessageQueue component to receive a message from a message queue. To run the sample you have to have Message Queuing installed on your system. The sample is a command-line application that takes one command-line argument. The argument is the name of a public message queue on your local machine. For example, you can run it as follows (first send a message to the queue using the MQSend sample):
> MQReceive.exe MyQueue
The sample application will receive and output to the console the first message from the queue. In its simplest form, receiving a message from a message queue involves:
  1. Creating an instance of the MessageQueue component, setting its Path, and initializing the Formatter's TargetTypeNames property:

    
    Dim mq As MessageQueue = new MessageQueue(mqPath)
    Dim formatter As XmlMessageFormatter = CType(mq.Formatter,XmlMessageFormatter)
    formatter.TargetTypeNames = new String(){"System.String"}
    
    VB


  2. Calling Receive to receive the message:

    
    Dim m As Message = mq.Receive(New TimeSpan(0,0,3))
    Console.WriteLine(CStr(m.Body))
    
    VB

Example

VB MQReceive.exe
View Source

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Services\MessageQueue\MQReceive\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.