-->

WCF / WebService to act as Listener for MQ Message

2020-08-10 07:57发布

问题:

Perhaps I am barking up the wrong tree - but I have a set of services (WebAPI and WCF) that use WebSphere MQ to interact with other systems.

This works without issue - until I now need to find a way of listening for messages on one of the queues.

Is this even possible, or do I need to go down the windows Service route?

回答1:

Your problem can be broken down into two distinct elements:

  1. How to integrate MQ with a WCF-supported transport
  2. How to expose a WCF endpoint over this transport

To address the first issue, you should look at the MQ-MSMQ bridge which ships with Host Integration Server up to version 2009 (not R2), which allows you to have messages delivered to MQSeries queues forwarded to local MSMQs in windows. Although this feature is deprecated it's probably the easiest way if you have a MSDN license.

Another way of addressing this issue is to use BizTalk server which ships with a MQSeries adapter, though unless you're using BizTalk currently in your enterprise I would avoid.

The last way you could do this is to program directly against the MQSeries .NET client libraries or via the XMS client.

If you manage to solve the first issue then solving the second one is easy enough. You can expose one way WCF service operations over msmq transport by using the netMsmqBinding (for WCF on both ends), or msmqIntegrationBinding for clients using System.Messaging or native msmq COM libraries.

This in-effect acts as a listener service, with messages being handled by the service operation.



回答2:

You could write a Windows service that is continually calling MQ Get on the queue, and invokes a WCF service to process the message. Or you could write a trigger program (a console application) that MQ will launch for you when a message arrives, that invokes the WCF service.



回答3:

I might be just better at googling than you are, but I seem to have found the answer here.

Seems you want to load the IBM binding configuration in you app.config

<extensions>
  <bindingElementExtensions>
    <add name="IBM.XMS.WCF.SoapJmsIbmTransportChannel" 
           type="IBM.XMS.WCF.SoapJmsIbmTransportBindingElementConfig, IBM.XMS.WCF, Version=7.5.0.0, Culture=neutral, PublicKeyToken=8c7c0be90afcd8ba"/>
  </bindingElementExtensions>
</extensions>

Then you can add a WebSphere WCF binding config.

<bindings>
  <customBinding>
    <binding name="CustomBinding_WMQ">
      <textMessageEncoding messageVersion="Soap11" />
      <IBM.XMS.WCF.SoapJmsIbmTransportChannel />
    </binding>
  </customBinding>
</bindings>


回答4:

how to get connect with ibm websphere mq by using c#.net

Perhaps you could use the above answer and within that queue consumer app create a "Service Reference" to your WCF service.