What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7330 |  Welcome, Guest!   Register  Login
Home > Articles > WCF > Message Queuing in WCF

Message Queuing in WCF

Article posted by Anup1252000 on 11/5/2009 | Views: 11912 | Category: WCF | Level: Beginner red flag


In this article you are going to see how to use Message Queuing in WCF.

Introduction

Windows Communication Foundation provides support for queued calls using NetMsmqBinding. Instead of transporting a message over TCP or HTTP, Windows Communication Foundation transports the message over Microsoft Message Queuing (MSMQ). Instead of sending the Windows Communication Foundation message to a live service, the client posts the message to an MSMQ queue. All the client sees and interacts with is the queue, not a service endpoint. As a result, the calls are inherently asynchronous and disconnected. The calls will execute when the service processes the messages at some time in the future.

Above paragraph is from http://msdn.microsoft.com/en-us/magazine/cc163482.aspx article.
Lets go through this application Step by Step

Step1:

        In this application, we are using console application. Open VS 2008>New>Project>Console Application>choose your programming Language, here i am using c# but you can use VB>Give the name of the project as MSMQ Server(This is our Server)>OK

Step2:

        Make sure that you have installed Message Queuing. If not use your windows OS, Go to control Panel>Add or Remove Programs>Add Windows Component>There you can see Message Queuing>Install Message Queuing.

Step3:

        Now in the MSMQ Server, give a Reference to System.ServiceModel.

Step4:

        Now the time has come to write our Service contract,operation contract. Here i am write simple operation Contract. where it prints just "HI".Where, I am concentrating more on configuration part. 



Here you can see in the OperationContract, i set IsOneWay=true why because this NetMsmqBinding only supports one way communication. But it is different where you can use Duplex or Request-reply communication. For that You need to customize the things. But in this application, We are just looking at one way contract.

Step5:

        Now add Application Configuration file in your application(app.config). I suggest you to use WCF Service Configuration Editor Tool. Because of the lack of time i am not showing you how to use this tool. Just go through this article http://jeffbarnes.net/blog/post/2007/02/28/WCF-Configuration-Editor.aspx. Here is my app.config File
 



Here you can see the endpoint address like net.msmq://ahosur1/private/anup which is of format net.msmq://machine name/private/queuename. In this we are setting the security to None. One more thing is appsettings, there in the value filed i gave the path of the Message Queue. IMPORTANT thing here in endpoint address of netmsmq you should specify the queue path. Otherwise it will tell like whether you installed Message Queue properly or not. 


Step6:

        Now write the service host and some other things. First you give reference to System.Messaging. 


Run the server and check any error if any fix those.


Step7:
        Now we are using a tool called svcutil. 
        You need to type in VS command Prompt like this
        svcutil /out:proxy.cs /config:app.config http://localhost:8003/Service
        It will generate proxy.cs and app.config.


Step8:
        Now lets create a client application. go to File>New>Project>ConsoleApp>give the name as MSMQ client>OK
        Give the Reference to System.ServiceModel.Copy and paste the proxy.cs and app.config in to the client app.

Step9:
        Now write the client like this
 


iserviceClient is noting but the class name of the proxy.cs.

Step10:
          Now let this application. In this case we are just running the client 3 times.


Now check the Message queue.
Start>run>compmgmt.msc>services and application>message queue>under private queue>my queuename is anup it may be different in your application>queue message.




Here you can see 3 messages in the message queue.

Now lets run Server


Here you can see 3 hi messages. 

Now lets got to message queue again and refresh that screen u can see blank screen.




I hope you people like this application.

Reference:
Standard definition of Queued Calls has been taken exactly from http://msdn.microsoft.com/en-us/magazine/cc163482.aspx and credit goes to this article.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About anup hosur

Experience:2 year(s)
Home page:
Member since:Saturday, August 01, 2009
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points
Related Posts

In this article we will discuss how we can enable certificates on WCF service. WCF has two modes by which it transfers data one is the transport and the other is the message. This tutorial will concentrate on how we can enable certificates on message mode of data transfer.

This article will explain creation of custom binding in WCF services.

In this article, We are going to see how to use Channel factory in WCF.

In this article, we are going to see how to use Ajax Enabled WCF Service in a website.

I came across a question last week on how we can upload a file using a WCF service, So thought of solving through an example.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 4:50:43 PM