none
TransactionIsolationLevel requires at least one operation with TransactionScopeRequired set to true. RRS feed

  • Question

  • Why does the following code fail with the following error:

    The service 'Service0001' is configured with a TransactionIsolationLevel but no operations are configured with TransactionScopeRequired set to true. TransactionIsolationLevel requires at least one operation with TransactionScopeRequired set to true.

    using System.ServiceModel;
    using System.ServiceModel.Description;
    using System.Transactions;
    namespace ConsoleApplication29
    {
        [ServiceContract()]
        public interface IService0001
        {
            [OperationContract]
            void Operation0001();
        }
    
        [ServiceBehavior(TransactionIsolationLevel = IsolationLevel.ReadCommitted)]
        public class Service0001 : IService0001
        {
            [OperationBehavior(TransactionScopeRequired = true)]
            public void Operation0001()
            {
            }
        }
    
    
        class Program
        {
            static void Main(string[] args)
            {
                var host = new ServiceHost(typeof(Service0001));
                var ep = new ServiceEndpoint(ContractDescription.GetContract(typeof(IService0001)), new BasicHttpBinding(), new EndpointAddress("http://localhost:19999/Url"));
                host.AddServiceEndpoint(ep);
                host.Open();
            }
        }
    }

    If I make a slight alteration, which makes no significant difference to my knowledge, it goes off without a hitch:

    using System.ServiceModel;
    using System.ServiceModel.Description;
    using System.Transactions;
    using System;
    namespace ConsoleApplication29
    {
        [ServiceContract()]
        public interface IService0001
        {
            [OperationContract]
            void Operation0001();
        }
    
        [ServiceBehavior(TransactionIsolationLevel = IsolationLevel.ReadCommitted)]
        public class Service0001 : IService0001
        {
            [OperationBehavior(TransactionScopeRequired = true)]
            public void Operation0001()
            {
            }
        }
    
    
        class Program
        {
            static void Main(string[] args)
            {
                var host = new ServiceHost(typeof(Service0001));
                host.AddServiceEndpoint(typeof(IService0001), new BasicHttpBinding(), new Uri("http://localhost:19999/Url"));
                host.Open();
            }
        }
    }

    Maybe a bug with Framework? I'm using Framework 4.0 (which is evident from my use of "AddServiceEndpoint" in the first code block anyway)

    Thanks!


    Friday, May 31, 2013 1:25 PM

Answers

All replies