Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Sat, 01-Nov-2014 Authors
All Time Authors
Sourav.Kayal
39750
Sheonarayan
38050
Niladri.Biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads
 Article

Message Queuing in WCF

Anup1252000
Posted by under WCF category on for Beginner level | Views : 14324 red flag
If you found plagiarised (copied) or inappropriate content,
please let us know the original source along with your correct email id (to communicate) for further action.
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.
Page copy protected against web site content infringement by Copyscape
About the Author

Anup1252000

Full Name: anup hosur
Member Level:
Member Status: Member
Member Since: 8/1/2009 2:37:23 AM
Country: India

Login to vote for this post.
Found interesting? Add this to:


Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)