【问题标题】:MSMQ service not reading the queueMSMQ 服务未读取队列
【发布时间】:2012-10-03 03:36:08
【问题描述】:

我正在使用 MSMQ Web 服务从队列中读取数据并将其存储在数据库中。目前我正在使用 Visual Studio 2010 运行该服务(这是问题吗?)。代码sn-ps如下。

合同

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

实施

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

配置

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

附加信息

  • 我尝试过使用不同的队列名称。像 .\Private$\Service1 和 .\Private$\Service1.svc

    • 消息队列、消息队列触发器、Net.Msmq Listner 适配器和 WAS 服务正在运行
    • 我明确地将消息插入队列

--

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

原因是,我正在从另一个调用 MSMQ 网络服务 网络服务。当我调用 MSMQ 服务时,它不是将消息插入队列,而是调用 MSMQ 服务。

【问题讨论】:

    标签: c# .net msmq


    【解决方案1】:

    检查队列名称格式的拼写。

    代替

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

    你应该试试这个:

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

    ... 当然,这里 YOURMACHINENAME 需要替换为持有队列的机器的名称。 :-)

    请注意,第一部分区分大小写

    【讨论】:

      【解决方案2】:

      我相信这也会起作用(将您的单反斜杠更改为双反斜杠)。而且您不需要使用机器名称(因此,当您将其从本地盒子移动到任何地方时,您无需更改代码)。

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

      【讨论】:

        猜你喜欢
        • 2010-09-21
        • 2010-12-07
        • 2013-12-31
        • 1970-01-01
        • 2015-03-04
        • 1970-01-01
        • 2011-04-02
        • 1970-01-01
        • 2012-03-18
        相关资源
        最近更新 更多