Kanishka
Kanishka

Reputation: 1147

MSMQ service not reading the queue

I'm using MSMQ web service to read data from a queue and store it in database. Currently I am running the service using Visual Studio 2010 (Is this the issue?). The code snippets are below.

Contract

[ServiceContract]
public interface IService1
{
    [OperationContract(IsOneWay = true,Action="*")]
    void DOWork(MsmqMessage<Param> p);
}

Implementation

public class Service1:IService1
{
    [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
    public void DoWork(Param p)
    {
        new Service1BL().DoWork(p);
    }
}

Config

<service name="NameSpace.Service1" behaviorConfiguration="MSMQServiceBehavior">
                <endpoint address="net.msmq://localhost/private/Service1" binding="netMsmqBinding" bindingConfiguration="PoisonBinding" contract="IService1"/>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>

<behavior name="MSMQServiceBehavior">
    <serviceDebug includeExceptionDetailInFaults="true"/>
    <serviceMetadata httpGetEnabled="True"/>
   </behavior>

<netMsmqBinding>
                <binding name="PoisonBinding" receiveRetryCount="1" maxRetryCycles="5" retryCycleDelay="00:00:05" receiveErrorHandling="Fault">
                    <security mode="None"/>
                </binding>
            </netMsmqBinding>

Additional Info

--

MessageQueue queue = new MessageQueue(@".\private$\service1");
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
   queue.Send(p, MessageQueueTransactionType.Single);
   queue.Close();
   scope.Complete();
}

The reason for this was, I am calling the MSMQ webservice from another web service. When I make the call to the MSMQ service, instead of inserting the messages into the queue, it was invoking the MSMQ service.

Upvotes: 2

Views: 1191

Answers (2)

Glade Mellor
Glade Mellor

Reputation: 1366

I believe that this will work as well (change your single backslash to double backslashes). And you don't need to use the machine name (so when you move it from your local box to wherever, you don't need to change your code).

MessageQueue queue = new MessageQueue(@".\\private$\\service1")

Upvotes: 1

Jens H
Jens H

Reputation: 4632

Check the spelling of your queue name format.

Instead of

MessageQueue queue = new MessageQueue(@".\private$\service1");

you should instead try this:

MessageQueue queue = new MessageQueue(@"FormatName:DIRECT=OS:YOURMACHINENAME\private$\service1");

... where YOURMACHINENAME needs, of course, to be substituted with the name of the machine that holds the queue. :-)

Please note that the first part is case-sensitive.

Upvotes: 4

Related Questions