Search code examples
wcfexceptionmessage-queuemsmq

One Way WCF Contract, MSMQ and Throwing Exceptions


I created a WCF service contract that works against MSMQ. Since it is MSMQ, I use one-way communication:

[OperationContract(IsOneWay = true)]

In my service implementation, I have OperationBehavior to automatically commit transactions:

[OperationBehavior(TransactionAutoComplete = true, TransactionScopeRequired = true)]

This makes sure WCF handles any exceptions by putting the message on a retry queue (per my configuration). It seems odd to be throwing an exception from a one-way operation. Is this the correct way to tell WCF not to commit the transaction?


Solution

  • After some research, I found that throwing an exception is the only way to tell WCF to use the built-in retry sub-queue. This exception is swallowed by WCF. It is also used to make sure the transaction isn't auto-completed.