2
votes

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

  • I have tried with different queue names. Like .\Private$\Service1 and .\Private$\Service1.svc

    • Message Queuing, Message Queuing Triggers, Net.Msmq Listner adapter and WAS services are running
    • I am explicitly inserting the messages into the queue

--

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.

2

2 Answers

4
votes

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.

1
votes

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")