ASP.NET
  Home arrow ASP.NET arrow Using MSMQ in Dot Net Using VB.Net Sending...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Using MSMQ in Dot Net Using VB.Net Sending and Receiving Messages Using MSMQ in Dot Net:
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2001-08-04

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using MSMQ in Dot Net Using VB.Net
    Sending and Receiving Messages Using MSMQ in Dot Net:

    author: Sreedhar Koganti 
    
    This example will help you to know how to send and receive messages using MSMQ.
    In Dot net, MSMQ provides a powerful set of services. These you can get from
    System.Messaging name space. In order to use MSMQ explorer our
    Dot Net IDE can also be used to add and remove messages form MSMQ.

    How you can use MSMQ:
    In order to use MSMQ first you have to install MSMQ in your machine.
    Since we are looking at MSMQ in Dot Net,
    you need to have Windows 2000 + Service Pack1, MSMQ, .NET Framework Beta1 and
    Visual Studio.NET .

    How to Use MSMQ:
    MSMQ Enterprise can be managed through the MSMQ Explorer.
    The MSMQ Explorer provides an interface for managing all machines in a
    MSMQ environment from a single point of control. This MSMQ Explorer
    you can get from Computer Management/Services and Applications/MessageQueing.

    Here I am trying to show a simple Example in VS.Net(VB).
    In this example I am using a Windows Application in the C# Environment.
    This example will help you to know how to send and receive messages using MSMQ.
    In this example I am basically using System.Messaging name space to manage the
    messages using msmq.

    To do that created a Windows application in VB using VS.net.

    In that i take a form module and I kept two buttons one for sending
    data and one for receiving data. And I also used a text box.While sending
    message i am taking message form the textbox.Button one is used to send message.
    Other button will be used to receive the data.

    To use the MSMQ name space System.Messaging, you have to go to Tools and
    Component Tab, then Drag and Drop the MessageQueue to the Form (Design View).
    Once you add it, as shown below, code will be added to your application


    Private WithEvents MessageQueue1 As System.Messaging.MessageQueue
    The above code will be added in public class Form1 : System.WinForms.Form
    and one more important line
    Me.MessageQueue1 = New System.Messaging.MessageQueue()
    will be added in Private Sub InitializeComponent()

    While your application initializes it will create the messageQueue1 .
    Once your object has been Created or Instantiated you can use it's methods and Properties.

    In our example we are trying to Send a message to "Smile" Pirvate Queue.
    "Smile"is a Queue name which we are using in the example. It's not a system Queue.

    The code below is used for sending the message to a queue when you click Button1 button.

    ****************************

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim q As MessageQueue
    If MessageQueue.Exists(".Private$Smile") Then
    q = New MessageQueue(".Private$Smile")
    Else
    q = MessageQueue.Create(".Private$Smile")
    End If

    Dim BW As New BinaryWriter(New MemoryStream())
    bw.Write(textbox1.Text)
    Dim m As New Messaging.Message()
    m.BodyStream = BW.BaseStream
    m.Label = "Sri Test Message"

    q.Send(m)
    msgbox("Message sent successfully",
    Microsoft.VisualBasic.MsgBoxStyle.Information, "MSMQ Message")

    End Sub

    ******************************

    When you click the command one first i am checking for Queue if queue is not there
    then i am creating the Queue , if queue is the i am sending the message to the queue
    usingn Send method.
    Send Can basically will have two arguments a) Message b) Label for that message.

    Button Two will help you to receive the messages:
    ******************************

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim q As MessageQueue
    Dim m As Messaging.Message
    Dim Br As BinaryReader
    Dim x As String

    If MessageQueue.Exists(".Private$Smile") Then
    q = New MessageQueue(".Private$Smile")
    Else
    q = MessageQueue.Create(".Private$Smile")
    End If


    Try
    m = q.Receive(New TimeSpan(0, 0, 3))
    Br = New BinaryReader(m.BodyStream)
    x = New String(Br.ReadChars(CInt(m.BodyStream.Length)))
    Catch
    x = "(no message)"

    End Try
    msgbox(x, Microsoft.VisualBasic.MsgBoxStyle.Information, "MSMQ Message")

    End Sub

    ********************************
    If you look into the code, basically I am testing for the existence of the Smile Private Queue.
    If it is not there, I am popping up a message box. If it is there, then I am instantiating
    a PostMessage as a Message Queue.

    Here I have to explain one thing. The message object holds the result of the received message.
    So here I am using m as the message object, and we also created a TimeSpan object from the
    System name space. The TimeSpan object will tell how long to wait for the Receive
    method before timing out (hours, minutes, seconds).
    Before .Net, we could simply set a message object Body property to a string value.
    But in Dot Net the data will be automatically wrapped in XML using SOAP encoding.
    It makes consistent with other languages with in Dot Net.

    Note:
    Take care with the following Steps:
    1. Must install MSMQ on your machine.
    2. Drag and Drop the Message Queue into your Design Form.
    3. You must be using System.Messaging;
    4. Must declare a message for receiving messages. Here we declared as m.
    5. Build the code before running.


    Author:
    Sreedhar Koganti
    Working in Unisys as a Technical Team Lead
    Expertixe in ASP,COM+,XML,SOAP,NTService,VB, Drop of .Net
    Article Writer in asptoday.com,Aspalliance.com,aspfree.com
    ***********************************************************


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP.NET Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server.
    FREE! Go There Now!


    NEW! Project and Portfolio Management Executive Resource Kit

    Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Testing eKits

    Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing.
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET ARTICLES

    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT