WCF service reading from MSMQ

I'm trying to make a WCF app that consumes Messages from the MQ. Preferrably the MQ would sent the messages to a WCF service, so that when ever so one drops a message in the queue the MQ will try to and sent it to a WCF service. I've seen a few examples but can't seem to get any off them to work.

Below is my configuration for the service that needs to be called.

Do I have to set something up in the MSMQ? (i suppose so but none of the examples i found on MSDN.com said anything about that)

<system.serviceModel>

<services>

<service

name="ConsumerForm.OrderProcessor" >

<host>

<baseAddresses>

<addbaseAddress="msmq.formatnameBig SmileIRECT=OS:.\private$\Orders"/>

<addbaseAddress="http://localhost:8080/Orders"/>

</baseAddresses>

</host>

<endpointaddress=""

binding="msmqIntegrationBinding"

bindingConfiguration="OrderProcessorBinding"

contract="Contracts.IOrderProcessor">

</endpoint>

</service>

</services>

<bindings>

<msmqIntegrationBinding>

<bindingname="OrderProcessorBinding" >

<securitymode="None" />

</binding>

</msmqIntegrationBinding>

</bindings>

</system.serviceModel >

[2463 byte] By [RuneFS] at [2008-1-9]
# 1
Might sound silly...but have you created the MSMQ in the first place?
RamjeeTangutur at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2

Hi, it's a little hard to tell what could be happening without an error message or an exception. If you could post what exception you're seeing or what actually happens with your service it would help in determining the problem. Have any of the samples worked for you?

I also notice you're using the MsmqIntegrationBinding. Is this because your messages are sent by a System.Messaging or by a native MSMQ application? If your sender is a WCF client, you might want to use the NetMsmqBinding.

SorinAlexander-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3

I agree it's a little hard without an error message or exception, and that's basically my problem. I don't get either and nothing is happening. All I can see is that the client is delivering the messages to the queue and the service is not acting upon them. I've used eventvwr to see if there was any messages there but found nothing and the webservice is not getting invoked at all, so not much informaqtion to gather there. I've tested the WS with out MSMQ and it works fine (the only alteration was to the message signature so it didn't accept a Message<T> but an object of type T)

I deliberately use integrationbinding cause the service can not rely on the client being wcf, it might be a none .NET app delivering the MSMQ-messages to the queue.

RuneFS at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4

I've just tryed it out with netmsmqbinding instead and it got me a little further (all though i would like to use integration instead) my problem now is that every single property of the message object the service receives is throwing a nullreferenceexception. Any suggestions to what I can do to find the reason for this behaviour?

only changes i'va made is to change the above configuration so the endpoint now has the following attributes changed

address="net.msmq://localhost/private/Orders"

binding="netMsmqBinding"

Thx for any suggestions

RuneFS at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 5

Hi, sorry for the late reply. Here are some things to consider. When using the integration binding, you need to decorate your contract with the [ServiceKnownType(typeof(T))] attribute. You also need to have the Action="*" parameter set on your [OperationContract] attribute. Finally, the operation takes a parameter of type MsmqMessage<T>.

For example, the contract below contains one method (Operation1), which expects a message containing an int.

[ServiceContract]

[ServiceKnownType(typeof(int))]

public interface IContract

{

[OperationContract(IsOneWay = true, Action = "*")]

void Operation1(MsmqMessage<int> message);

}

The NetMsmqBinding does not expose all the native MSMQ message parameters. This might be why you're seeing the NullReferenceExceptions.

Lastly, you mentioned that you have a webservice. Are you attempting to webhost this application? If so, I would suggest trying to get it working selfhosted first as it would be much easier to debug.

SorinAlexander-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 6

I'm having a similar problem trying to consume input from a VB NET app writing to a local private MSMQ queue that already exists, and using a separate VB NET test Windows app to write simple string messages to the queue. With netMSMQBinding the WCF service consumes items in the queue at startup and as added, but no code ever gets executed in the service. I had to create a new bindingConfiguration (NewBinding0) with durable and exactlyOnce set false, in order to get it to run at all. I've tried accepting different types eg messaging.message to access message.body.tostring, and I've tried using msmqIntegrationBinding. So far anything other than code below has resulted in startup problems. It returns errors e.g. the operation service contract is not configured properly, or the cannot be serialized. Have not found any decent VB based examples other than various snippets out of context. Here's the service block in the app.config and the full app code. Would much appreciate any pointers offered.

<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="NewBinding0" durable="false" exactlyOnce="false" />
</netMsmqBinding>
</bindings>
<behaviors />
<services>
<service behaviorConfiguration="" name="WCFDemoServiceViaMSMQ.Module1+MSMQReceive">
<endpoint address="net.msmq://localhost/testq" binding="netMsmqBinding"
bindingConfiguration="NewBinding0" name="" contract="WCFDemoServiceViaMSMQ.Module1+iMSMQReceive" />
</service>
</services>
</system.serviceModel>

Imports System.ServiceModel
Imports System.Messaging
Module Module1
<ServiceContract()> _
Public Interface iMSMQReceive
<OperationContract(IsOneWay:=True, Action:="*")> _
Sub Receive(ByVal s As String)
End Interface
Public Class MSMQReceive
Implements iMSMQReceive
Public Sub Receive(ByVal s As String) Implements iMSMQReceive.Receive
Try
BugsTrace("ReceiveData: " & s)
Catch ex As Exception
BugsTrace("Receive exception: " & ex.Message)
End Try
End Sub
End Class
Sub Main()
BugsTrace("=== WCFDemoServiceViaMSMQ started === ")
BugsTrace("Opening ServiceHost for MSMQReceive")
Dim oHost As New ServiceHost(GetType(MSMQReceive))
oHost.Open()
BugsTrace("Opened, state is: " & oHost.State.ToString())
BugsTrace("Hit Return to close service")
System.Console.ReadLine()
BugsTrace("Closed service")
oHost.Close()
End Sub
Private Sub BugsTrace(ByVal s As String)
System.Console.WriteLine(Now.ToString & " - " & s)
End Sub
End Module

noeldp at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 7
In our case the WCF service is hosted in a Windows Service. The Windows Service Starts and then Stops with "nothing to do" unless there are Messages already in the Queue when it starts, in that case it process all the messages and shuts down again.

All the documentation:

http://msdn2.microsoft.com/en-us/library/bb332338.aspx#msdnwcfhc_topic4
http://msdn2.microsoft.com/en-us/library/ms730158.aspx
http://msdn.microsoft.com/msdnmag/issues/07/02/Foundations/default.aspx

implies that Windows Service hosting supports all message types, however, this does not appear to be the case.

Anyone else experiencing this issue?

jdrake3 at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 8
Our real issue was permissions to the underlying Queue. Once those were taken care of the service was able to run. Also there is now some certainty that queue messages were not actually being processed by the Service before this issue was taken care of.

Specifically the Run As account for the service required permissions to the queue.

FYI

jdrake3 at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified