MSMQ Listeners using WCF
Asked Answered
P

1

8

Do anybody knows how to implement MSMQ Listeners using WCF ?

i have 2 wcf services built, 1 for sending data to MSMQ queue and another is called by MSMQ listener when there is an insertion in MSMQ queue.Now i wanna know how and where i need to write this MSMQ listener.

Psychographer answered 12/10, 2011 at 6:11 Comment(2)
So much information on SO about this: https://mcmap.net/q/1472073/-using-windows-services-to-process-msmq-messages-via-wcf https://mcmap.net/q/1443599/-msmq-and-wcf-service https://mcmap.net/q/1472074/-msmq-wcf-and-flaky-serversPothead
i have 2 wcf services built, 1 for sending data to MSMQ queue and another is called by MSMQ listener when there is an insertion in MSMQ queue.Now i wanna know how and where i need to write this MSMQ listener.Psychographer
C
4

You do not need to manually implement a queue listener on your service.

Simply by creating your service operation contract you are specifying the handler method which will be called when a message arrives on the local queue.

You probably (or should) have something like this:

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

This will ensure that the method HandleMyMessage() in your service implementation will be called when a message is delivered.

UPDATE

In response to your question in the comment below, to define 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

Culley answered 12/10, 2011 at 7:35 Comment(2)
Thanks a lot hugh. So you mean to say only one service fulfills both send and receive operations right?Psychographer
Where do you specify queuename, to which i need to listen?Psychographer

© 2022 - 2024 — McMap. All rights reserved.