【问题标题】:MsmqException (0xC00E0051) after 60 seconds60 秒后 MsmqException (0xC00E0051)
【发布时间】:2011-07-14 06:49:28
【问题描述】:

我将 netMsmqBinding 与事务队列一起使用,尽管调用 WCF 服务没有问题,但该服务在消息处理后仅 60 秒就抛出 MsmqException。

这是个例外:

System.ServiceModel.MsmqException (0xC00E0051):从队列接收消息时出错:无法识别的错误 -1072824239 (0xc00e0051)。确保 MSMQ 已安装并正在运行。确保队列可用于接收。在 System.ServiceModel.Channels.MsmqInputChannelBase.TryReceive(时间跨度 超时,消息和消息)在 System.ServiceModel.Dispatcher.InputChannelBinder.TryReceive(时间跨度 超时,请求上下文和请求上下文)在 System.ServiceModel.Dispatcher.ErrorHandlingReceiver.TryReceive(时间跨度 超时,RequestContext&requestContext)

我做了一些研究,调试和跟踪,我发现当收到一条新消息时,会打开两个事务,第一个在服务执行后提交,但第二个从未提交,所以然后,60 秒后,DTC 中止它并抛出 MsmqException。 这是操作定义:

[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void SomeOperation(SomeParameter parameter)
{
  // business logic
}

关于正在发生的事情有什么想法,我该如何解决这个问题?

更新:

配置:

<netMsmqBinding>
  <binding name="TransactionalMsmqBinding" exactlyOnce="true" deadLetterQueue="System" receiveErrorHandling="Move">
    <security mode="None"/>
  </binding>
</netMsmqBinding>
...
<service name="SomeNamespace.SomeService">
  <endpoint contract="SomeNamespace.ISomeService" bindingConfiguration="TransactionalMsmqBinding" binding="netMsmqBinding" address="net.msmq://localhost/private/services/someservice.svc">
  </endpoint>
  <endpoint contract="SomeNamespace.IAnotherService" bindingConfiguration="TransactionalMsmqBinding" binding="netMsmqBinding" address="net.msmq://localhost/private/services/anotherservice.svc">
  </endpoint>
</service>

服务实现:

[ExceptionShieldingBehavior(typeof(ArgumentValidationException), typeof(ValidationServiceException))]
[AuthorizationAndAuditBehaviour]
[ServiceBehavior(Namespace = GlobalConstants.ServiceContractNamespace)]
public class SomeService: ISomeService, IAnotherService
{
  [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
  public void SomeOperation(SomeParameter parameter)
  {
    // business logic
  }

  [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
  public void AnotherOperation(AnotherParameter parameter)
  {
    // business logic
  }
}

服务合同:

[ServiceContract(Namespace = GlobalConstants.ServiceContractNamespace)]
public interface ISomeService
{
  [OperationContract(IsOneWay = true)]
  void SomeOperation(SomeParameter parameter);
}

[ServiceContract(Namespace = GlobalConstants.ServiceContractNamespace)]
public interface IAnotherService
{
  [OperationContract(IsOneWay = true)]
  void AnotherOperation(AnotherParameter parameter);
}

完整行为

  1. 客户端发送消息
  2. 服务已激活
  3. DTC 启动两个事务(我可以在 DTC 监视器和 TransactionManager.DistributedTransactionStarted 事件中看到它们)
  4. 第一个事务在操作完成后立即完成
  5. 第二个事务在 60 秒后中止(抛出 MsmqException)
  6. wcf 主机 (IIS) 有时会出现故障(我有一些代码到 automatically recover it,显然这种行为在 .net 4 中已经改变)
    • 如果主机被破坏并自动恢复,下一条消息将再次发生
    • 如果主机没有损坏,则第二次事务将不会在下一次开始,一切都会正常运行:)。
    • 如果我回收 AppPool,问题又出现了

【问题讨论】:

  • 您能展示一下:您的服务合同、服务配置和托管代码吗?
  • 0xC00E0051。 MQ_ERROR_TRANSACTION_SEQUENCE。 “交易的操作顺序不正确。” DTC 交易还涉及什么?
  • 嗨,Richard 和 John,我已经添加了更多详细信息,感谢您的回答。

标签: wcf msmq netmsmqbinding


【解决方案1】:

我找到了问题。

当我使用两个不同的 msmq 端点公开相同的服务时,由于某种奇怪的原因,SMSvcHost.exe 进程会激活 same 端点两次。

我刚刚写了一个解决方案的帖子:http://blog.jorgef.net/2011/07/msmqexception.html

希望对你有帮助。

豪尔赫

【讨论】:

  • 分享链接失效,能否请教解决方法。
猜你喜欢
  • 2018-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-23
  • 2011-07-22
  • 2016-09-19
相关资源
最近更新 更多