2011-07-14 41 views
3

我正在使用netMsmqBinding和事務性隊列,雖然調用WCF服務時沒有問題,但該服務僅在處理完消息後60秒才拋出MsmqException。60秒後MsmqException(0xC00E0051)

這是例外:

System.ServiceModel.MsmqException(0xC00E0051):當從隊列中接收消息時發生錯誤:無法識別錯誤 -1072824239(0xc00e0051)。確保MSMQ已安裝並正在運行。確保隊列可以從中接收。在在 System.ServiceModel.Dispatcher.ErrorHandlingReceiver System.ServiceModel.Channels.MsmqInputChannelBase.TryReceive(時間跨度 超時,消息&消息)在 System.ServiceModel.Dispatcher.InputChannelBinder.TryReceive(時間跨度 超時,RequestContext的&的RequestContext)。 TryReceive(時間跨度 超時,RequestContext的&的RequestContext)

我做了一些研究,調試和跟蹤,我發現,在收到新郵件時,兩筆交易被打開,第一個承諾只是AFTE r服務執行,但第二個從不提交,那麼在60秒後,DTC終止它拋出MsmqException。 這是操作的定義:

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

正在發生的事情的任何想法,我怎麼能解決這個問題呢?

UPDATE:

配置:

<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秒後中止
  6. wcf主機(IIS)有時會出錯(我有一些代碼爲automatically recover it,顯然這種行爲已經改變了。網4)
    • 如果主機被打破,自動恢復,都將再次下一條消息
    • 如果主機也不會斷裂發生,第二個事務將不會啓動下一次,一切都將沒有問題的工作: )。
    • 如果我回收程序池,這個問題再次啓動
+0

你可以顯示:你的服務合同,服務配置和託管代碼? –

+0

0xC00E0051。 MQ_ERROR_TRANSACTION_SEQUENCE。 「交易的操作順序不正確。」 DTC交易涉及什麼? –

+0

嗨理查德和約翰,我已經添加了更多的細節,謝謝你的回答。 –

回答

1

我已經找到了問題。

由於我使用兩個不同的msmq端點公開相同的服務,出於某種奇怪的原因,SMSvcHost.exe進程激活了兩次相同的端點

我剛纔寫與解決方案後:http://blog.jorgef.net/2011/07/msmqexception.html

我希望它能幫助。

豪爾赫