Question

I have a windows service that picks up messages from various MSMQs. The service picks up the messages from the queues, and then executes a specific workflow based on the queue the message came in from. Is it possible to configure a WCF service to accept a message from an endpoint and place it in a queue? I would like for the service to have multiple endpoints, and depending on which endpoint received the message, the message would be placed in a different queue. I have seen things about netMsmqBinding but so far I haven't been able to determine if this is meant for the use I am thinking about.

Any help is appreciated,

Mike

Was it helpful?

Solution 2

The way I was able to go about this was by creating a custom ServiceHost class that I could pass a configuration name to. This is an alternative to the default implementation that uses the Service Implementation type name to locate the configuration. This allowed me to run multiple instances of the same implementation on the same machine. In addition to that, inside the custom service class I added a custom MessageInspector that would attach itself to every endpoint to listen for messages. I then use the IDispatchMessageInspector.AfterReceiveRequest() method to take the incoming message and then place it into a queue that I define inside my configuration. A little complicated, but it works perfectly for our scenario.

OTHER TIPS

Am I getting this correctly - you want to have

  • a WCF service exposed to the outside world using multiple endpoints
  • depending on which endpoint the message comes into the WCF service, it should put those messages into separate MSMQ queues?

You can definitely have a WCF service that will expose any number of endpoints to the outside and that would drop incoming messages into an MSMQ queue. I'm just not sure whether you'll be able inside the WCF service method to know which endpoint the request came in on..... typically, the WCF service class doesn't know anything about where the request came from (and typically doesn't need to know...).

I see a few approaches to this:

  • have multiple services, one for each (type of) endpoint; they can share all their code and everything, but if you separate this into separate service classes, then each service class would inherently know what endpoint it serves, and thus could know what MSMQ queue to put the info into

  • find a way to send some header information along with the message that somehow tells you where to put the messages

  • in WCF 4.0, you might be able to do something with the new WCF Routing Service.... not quite sure how that would work, however - since it would also require some kind of "hint" to know which endpoint it was called on and how to route the incoming message

net.msmq bindings allow a WCF client to write directly to an MSMQ queue, even if the queue-reading WCF service is not live -- it doesn't even have to exist. net.msmq bindings also allows automagic reading from queues. No use of MessageQueue to write to, or read from, a queue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top