Bug 14844 - ServiceHost.Open() shouldn't create Transaction
Summary: ServiceHost.Open() shouldn't create Transaction
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-09-19 04:24 UTC by foka
Modified: 2013-09-19 10:13 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample app that depicts the bug (791 bytes, text/plain)
2013-09-19 04:25 UTC, foka
Details

Description foka 2013-09-19 04:24:53 UTC
ServiceHost.Open() creates Transaction on Mono (checked on Linux). It shouldn't.
So after ServiceHost.Open() Transaction.Current != null on Mono, but it's null on MS.NET (expected behavior).

Please check the attached application. It writes "True" on MS.NET but "False" on Mono.
Compile it on Mono with: mcs Program.cs -r:System.Transactions -r:System.ServiceModel
Comment 1 foka 2013-09-19 04:25:53 UTC
Created attachment 4927 [details]
Sample app that depicts the bug
Comment 2 foka 2013-09-19 05:30:35 UTC
So here's why Mono creates the transaction.
ServiceHost uses ServiceDebugBehavior. This, in ServiceMetadataExtension, creates WSHttpBinding when eg. HttpHelpPageEnabled == true. And WSHttpBinding (actually WSHttpBindingBase) in CreateBindingElements always adds TransactionFlowBindingElement, which results in transaction created in ServiceHost.Open().
So if I disable help pages, the attached app would work fine. But the issue is more general. It doesn't happen only for ServiceDebugBehavior. Also for ServiceMetadataBehavior when I set its HttpGetEnabled = true.

So I think that the proper solution is to change WSHttpBindingBase.CreateBindingElements by removing TransactionFlowBindingElement from it.


Call stack for creating transaction in ServiceHost.Open():

System.Transactions.Transaction.set_CurrentInternal (value={System.Transactions.CommittableTransaction}) in /home/jmd/monoFoka/mcs/class/System.Transactions/System.Transactions/Transaction.cs:111
System.Transactions.TransactionScope.Initialize (scopeOption=System.Transactions.TransactionScopeOption.Required, tx={System.Transactions.CommittableTransaction}, options={System.Transactions.TransactionOptions}, interop=System.Transactions.EnterpriseServicesInteropOption.None, timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs:99
System.Transactions.TransactionScope..ctor (transaction={System.Transactions.CommittableTransaction}, timeout={00:01:00}, opt=System.Transactions.EnterpriseServicesInteropOption.None) in /home/jmd/monoFoka/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs:56
System.Transactions.TransactionScope..ctor (transaction={System.Transactions.CommittableTransaction}, timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs:48
System.Transactions.TransactionScope..ctor (transaction={System.Transactions.CommittableTransaction}) in /home/jmd/monoFoka/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs:42
System.ServiceModel.Channels.TransactionChannelListener<System.ServiceModel.Channels.IReplyChannel>.OnOpen (timeout={00:00:59.8774770}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/TransactionFlowBindingElement.cs:181
System.ServiceModel.Channels.CommunicationObject.Open (timeout={00:00:59.8774770}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:170
System.ServiceModel.Dispatcher.ListenerLoopManager.Setup (openTimeout={00:00:59.8774770}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs:353
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen (timeout={00:00:59.8774770}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs:300
System.ServiceModel.Channels.CommunicationObject.Open (timeout={00:00:59.8774770}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:170
System.ServiceModel.ServiceHostBase.OnOpen (timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:586
System.ServiceModel.Channels.CommunicationObject.Open (timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:170
System.ServiceModel.Channels.CommunicationObject.Open () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:164
HostOpenCreatesTransactionOnMono.Program.Main () in /home/jmd/public/HostOpenCreatesTransactionOnMono/HostOpenCreatesTransactionOnMono/Program.cs:27


Call for creating TransactionFlowBindingElement with ServiceDebugBehavior:

System.ServiceModel.Channels.TransactionFlowBindingElement..ctor (protocol={System.ServiceModel.TransactionProtocol.WSAtomicTransactionProtocol}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/TransactionFlowBindingElement.cs:50
System.ServiceModel.WSHttpBindingBase.CreateBindingElements () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/WSHttpBindingBase.cs:159
System.ServiceModel.WSHttpBinding.CreateBindingElements () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/WSHttpBinding.cs:80
System.ServiceModel.Channels.CustomBinding..ctor (binding={System.ServiceModel.WSHttpBinding}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CustomBinding.cs:60
System.ServiceModel.Description.ServiceMetadataExtension.EnsureChannelDispatcher (isMex=false, scheme="http", uri={http://localhost:1369/}, binding={System.ServiceModel.WSHttpBinding}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Description/ServiceMetadataExtension.cs:124
System.ServiceModel.Description.ServiceDebugBehavior.System.ServiceModel.Description.IServiceBehavior.ApplyDispatchBehavior (description={System.ServiceModel.Description.ServiceDescription}, serviceHostBase={System.ServiceModel.ServiceHost}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Description/ServiceDebugBehavior.cs:83
System.ServiceModel.ServiceHostBase.InitializeRuntime () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:476
System.ServiceModel.ServiceHostBase.OnOpen (timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:567
System.ServiceModel.Channels.CommunicationObject.Open (timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:170
System.ServiceModel.Channels.CommunicationObject.Open () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:164
HostOpenCreatesTransactionOnMono.Program.Main () in 


Call for creating TransactionFlowBindingElement withServiceMetadataBehavior:

System.ServiceModel.Channels.TransactionFlowBindingElement..ctor (protocol={System.ServiceModel.TransactionProtocol.WSAtomicTransactionProtocol}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/TransactionFlowBindingElement.cs:50
System.ServiceModel.WSHttpBindingBase.CreateBindingElements () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/WSHttpBindingBase.cs:159
System.ServiceModel.WSHttpBinding.CreateBindingElements () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/WSHttpBinding.cs:80
System.ServiceModel.Channels.CustomBinding..ctor (binding={System.ServiceModel.WSHttpBinding}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CustomBinding.cs:60
System.ServiceModel.Description.ServiceMetadataExtension.EnsureChannelDispatcher (isMex=true, scheme="http", uri={http://0.0.0.0:890/rest/IAreaManagerUserRestService}, binding={System.ServiceModel.WSHttpBinding}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Description/ServiceMetadataExtension.cs:124
System.ServiceModel.Description.ServiceMetadataBehavior.System.ServiceModel.Description.IServiceBehavior.ApplyDispatchBehavior (description={System.ServiceModel.Description.ServiceDescription}, serviceHostBase={System.ServiceModel.ServiceHost}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Description/ServiceMetadataBehavior.cs:99
System.ServiceModel.ServiceHostBase.InitializeRuntime () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:476
System.ServiceModel.ServiceHostBase.OnOpen (timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:567
System.ServiceModel.Channels.CommunicationObject.Open (timeout={00:01:00}) in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:170
System.ServiceModel.Channels.CommunicationObject.Open () in /home/jmd/monoFoka/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:164
Forcom.Perspectiv.Server.ServicesSupport.WcfServiceHelper.SetupRestService (scope={Autofac.Core.Lifetime.LifetimeScope}, serviceDescription={Forcom.Perspectiv.Server.ServicesSupport.Configuration.ServiceDescription}) in /home/jmd/Perspectiv/Forcom.Perspectiv.Server.Infrastructure/ServicesSupport/WcfServiceHelper.cs:121
Forcom.Perspectiv.Server.ServicesSupport.WcfServiceHelper.SetupRestService<Forcom.AreaManager.Server.Users.IAreaManagerUserRestService> (scope={Autofac.Core.Lifetime.LifetimeScope}, useRestPrefix=true) in /home/jmd/Perspectiv/Forcom.Perspectiv.Server.Infrastructure/ServicesSupport/WcfServiceHelper.cs:147
Forcom.AreaManager.Server.AreaManagerComponent.Activate (scope={Autofac.Core.Lifetime.LifetimeScope}) in /home/jmd/Perspectiv/Forcom.AreaManager.Module/AreaManagerComponent.cs:21
Forcom.Perspectiv.Server.Bootstrapper.ActivateComponents (scope={Autofac.Core.Lifetime.LifetimeScope}) in /home/jmd/Perspectiv/PerspectivServer/Bootstrapper.cs:186
Forcom.Perspectiv.Server.Bootstrapper.Start () in /home/jmd/Perspectiv/PerspectivServer/Bootstrapper.cs:100
Forcom.Perspectiv.Server.Bootstrapper.OnStart (args={string[0]}) in /home/jmd/Perspectiv/PerspectivServer/Bootstrapper.cs:60
Forcom.Perspectiv.Server.Bootstrapper.Main () in /home/jmd/Perspectiv/PerspectivServer/Bootstrapper.cs:48

Note You need to log in before you can comment on or make changes to this bug.