为什么排队的WCF消息会以静默方式消失?

Agi*_*Jon 8 .net c# wcf msmq netmsmqbinding

我在服务器THOR上设置了事务性MSMQ队列.我可以使用以下代码从工作站向该队列发送消息:

var queue = new MessageQueue("FormatName:Direct=OS:thor\\private\\myqueue");
using (var tx = new MessageQueueTransaction())
{
   tx.Begin();
   queue.Send("test", tx);
   tx.Commit();
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用WCF进行连接时,我的消息永远不会出现在队列中.这是我正在使用的配置:

<system.serviceModel>
  <bindings>
    <netMsmqBinding>
      <binding name="ClientNewsFeedServiceBinding" durable="true" exactlyOnce="true">
        <security mode="None" />
      </binding>
    </netMsmqBinding>
  </bindings>

  <client>
    <!-- NewsFeed Service -->
    <endpoint name="INewsFeedService"
              address="net.msmq://thor/private/myqueue"
              binding="netMsmqBinding"
              bindingConfiguration="ClientNewsFeedServiceBinding"
              contract="Service.Contract.INewsFeedService" />
  </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

和代码:

using (var tx = new TransactionScope())
{
   var cf = new ChannelFactory<INewsFeedService>("INewsFeedService");
   var service = cf.CreateChannel();
   service.TestMessage("test");
   ((IChannel)service).Close();
   tx.Complete();
}
Run Code Online (Sandbox Code Playgroud)

我没有任何例外,但是在THOR队列中没有发布消息.有任何想法吗?我甚至不知道如何调试它,因为它只是默默地失败.

UPDATE

如果我将我的MSMQ URI更改为'net.msmq:// localhost/private/myqueue',那么它将发布到我已设置的本地事务队列.队列本身的设置是相同的(例如,我执行相同的步骤来创建localhost和THOR队列).

Shi*_*iji 0

尝试在关闭通道之前完成交易范围。

当您关闭通道时,您将失去与它的联系,因此它有一个未提交的事务,该事务最终会被丢弃。