1

I have a requirement to be able to dynamically set the transaction timeout for a WCF service running over MSMQ. I am following the example on MSDN: http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.channeldispatcher.transactiontimeout.aspx. However, the timeout that I am setting does not seem to be working.

The code that I am using to set the TransactionTimeout property is below:

ServiceProperties properties = ...; // has a TransactionTimeout value for the service
var serviceHost = new ServiceHost(...);
serviceHost.Open();
var channelDispatchers =
    serviceHost.ChannelDispatchers.Select(
        cd => new ChannelDispatcher(cd.Listener)).ToArray();
foreach (var channelDispatcher in channelDispatchers)
{
    channelDispatcher.TransactionTimeout = properties.TransactionTimeout;
}

When I run my service and put a 2-minute delay in my service implementation, I receive a transaction enlistment error when I try to write to another MSMQ queue:

Exception: An error occurred while sending to the queue: The transaction specified cannot be enlisted. (-1072824232, 0xc00e0058).Ensure that MSMQ is installed and running. If you are sending to a local queue, ensure the queue exists with the required access mode and authorization.

Has anyone been able to get this to work in the past? Any ideas would be greatly appreciated.

Thank you in advance.

Michael Collins
  • 289
  • 2
  • 13
  • First thoughts: Check that the MSMQ and MS DTC services are running on ALL participating systems; Also check the access priviledges on the queue(s) that the users that your services are running with have the required read/ write priviledges. – Jens H Sep 25 '13 at 09:29
  • Everything is running locally. Permissions are correct. – Michael Collins Sep 25 '13 at 14:40

1 Answers1

0

I figured out the right approach. The correct way to do this is to find and modify the ServiceBehaviorAttribute object that is attached to the service description:

var transactionTimeout = TimeSpan.FromSeconds(...);
var behavior = serviceHost.Description.Behaviors.Find<ServiceBehaviorAttribute>();
behavior.TransactionTimeout = transactionTimeout.ToString();
serviceHost.Open();
Michael Collins
  • 289
  • 2
  • 13