Go to DotNetFunda.com
 Online : 1487 |  Welcome, Guest!   Login
 
Home > Articles > WCF > Message Queuing in WCF

  • Nominate yourself for "Agile Software Development using Scrum" online session for FREE, click here (Hurry, limited seats).

  • Download OOPS and ASP.NET Online training session video and PPT from here.

Submit Article | Articles Home | Search Articles |

Message Queuing in WCF

 Posted on: 11/5/2009 7:14:41 PM by Anup1252000 | Views: 1447 | Category: WCF | Level: Beginner | Print Article
In this article you are going to see how to use Message Queuing in WCF.

Ask all your .NET related questions/clarifications here to get quicker solution.

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.

Interesting?   Share and Bookmark this kick it on DotNetKicks.com


About anup hosur

Experience:2 year(s)
Home page:
Member since:Saturday, August 01, 2009
Level:Starter
Status: [Member]
Biography:
 Latest post(s) from Anup1252000

   ◘ Ajax Enabled WCF Service posted on 2/15/2010 1:10:10 AM
   ◘ Membership provider with WCF posted on 2/11/2010 7:00:47 AM
   ◘ Creating Multiple Channels in Channel factory in WCF posted on 2/11/2010 4:06:00 AM
   ◘ WCF Hosting in Windows Services posted on 1/28/2010 7:53:50 AM
   ◘ SSl with self hosted WCf Services posted on 11/25/2009 5:35:18 PM


Submit Article

About Us | The Team | Advertise | Contact Us | Feedback | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found copied contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)