Добавление операций поведения с помощью WCF

Я впервые использую WCF Facility для размещения пары сервисов, как в консольном приложении (для простой отладки), так и в IIS (для производства). Службы используют конечную точку net.msmq.

Вот как я размещаю сервис в консольном приложении (упрощенно):

using (var host = new DefaultServiceHostFactory() 
                    .CreateServiceHost(typeof(MyService).AssemblyQualifiedName, 
                                       new Uri[0])) 
    host.Open(); 

И вот как это зарегистрировано:

container.Register(Component.For<UserRequestService>()
                            .LifestylePerWcfOperation()) 

Я хотел бы добавить следующее поведение ко всем операциям:

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

Вот что я попробовал:

container.Register(Component.For<IOperationBehavior>() 
                            .UsingFactoryMethod(
                                x => new OperationBehaviorAttribute 
                                { 
                                    TransactionScopeRequired = true, 
                                    TransactionAutoComplete = true 
                                })); 

Но это приводит к исключению:

System.ArgumentException: The value could not be added to the collection, as the collection already contains an item of the same type: 'System.ServiceModel.OperationBehaviorAttribute'. This collection only supports one instance of each type.
Parameter name: item
   at System.Collections.Generic.KeyedByTypeCollection`1.InsertItem(Int32 index, TItem item)
   at Castle.Facilities.WcfIntegration.Internal.WcfUtils.AddBehaviors[T](IKernel kernel, WcfExtensionScope scope, KeyedByTypeCollection`1 behaviors, IWcfBurden burden, Predicate`1 predicate)
   at Castle.Facilities.WcfIntegration.WcfEndpointExtensions.Install(ServiceEndpoint endpoint, Boolean withContract, IKernel kernel, IWcfBurden burden)
   at Castle.Facilities.WcfIntegration.ServiceHostExtensions.Castle.Facilities.WcfIntegration.IWcfExtensionVisitor.VisitEndpointExtension(IWcfEndpointExtension extension)
   at Castle.Facilities.WcfIntegration.ServiceHostExtensions.Install(ICollection`1 extensions, IWcfBurden burden)
   at Castle.Facilities.WcfIntegration.AbstractServiceHostBuilder.ConfigureServiceHost(ServiceHost serviceHost, IWcfServiceModel serviceModel, ComponentModel model)
   at Castle.Facilities.WcfIntegration.AbstractServiceHostBuilder`1.Build(ComponentModel model, Uri[] baseAddresses)
   at Castle.Facilities.WcfIntegration.WindsorServiceHostFactory`1.CreateServiceHost(String constructorString, Uri[] baseAddresses)
   at Program.Main()

Есть идеи?

0 ответов

Другие вопросы по тегам