MSMQ listeners using WCF

Does anyone know how to implement MSMQ Listeners using WCF ?

I have 2 built-in wcf services, 1 to send data to the MSMQ queue, and the other is called by the MSMQ listener when the MSMQ queue is inserted. Now I want to know how and where I need to write this MSMQ listener.

+8
source share
2 answers

You do not need to manually inject the queue listener into your service.

By simply creating a service contract, you specify a handler method that will be called when the message arrives in the queue.

You probably (or should) have something like this:

[OperationContract(IsOneWay = true, Action = "*")] void HandleMyMessage (MsmqMessage<String> message); 

This ensures that the HandleMyMessage () method in your service implementation will be called upon message delivery.

UPDATE

In response to your question in the comment below, to determine the queue address, you can do this in the <System.ServiceModel> configuration:

 <services> <service name="Microsoft.ServiceModel.Samples.OrderProcessorService" behaviorConfiguration="CalculatorServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/> </baseAddresses> </host> <!-- Define NetMsmqEndpoint --> <endpoint address="net.msmq://localhost/private/ServiceModelSamplesTransacted" binding="netMsmqBinding" contract="Microsoft.ServiceModel.Samples.IOrderProcessor" /> <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex --> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> 

From here: http://msdn.microsoft.com/en-us/library/ms789032.aspx

+4
source

MSMQ binding is possible in WCF. You can refer to http://blogs.msdn.com/b/tomholl/archive/2008/07/12/msmq-wcf-and-iis-getting-them-to-play-nice-part-1.aspx , to get more details.

0
source

All Articles