locked
SendMessageChannelCache workflow extension does not work when ReceiveContextEnabledAttribute behavior is added RRS feed

  • Question

  • I have a custom WorkflowServiceHostFactory and host my WorkflowService xamlx in IIS 7.5/AppFabric 1.1 (.NET 4.5)

    I am using Windows Service Bus 1.1 and the WCF NetMessagingBinding. I enabled the caching of channels (SendMessageChannelCache) as that improves considerably the performance of sending to a service bus queue. Also I enabled the ReceiveContext behaviour to use PeekLock mode when receiving from a queue.

    However when ReceiveContext is enabled SendMessageChannelCache does not work.

    I am testing with a simple workflow service with only one Receive and one Send activity. Below the code of the custom WorkflowServiceHostFactory. If I comment out the following line the caching works: operation.Behaviors.Add(new ReceiveContextEnabledAttribute() { ManualControl = true });

    Thanks Michael

        public class MyWorkflowServiceHostFactory : WorkflowServiceHostFactory
        {
            protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses)
            {
                // Compile the C# expressions in the workflow by passing the Body to CompileExpressions.
                CompileExpressions(service.Body);
    
                WorkflowServiceHost host = base.CreateWorkflowServiceHost(service, baseAddresses);
                host.WorkflowExtensions.Add(new SendMessageChannelCache() { AllowUnsafeCaching = true });
    
                foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
                {
                    if (endpoint.Binding is NetMessagingBinding)
                    {
                        foreach (OperationDescription operation in endpoint.Contract.Operations)
                        {
                            ReceiveContextEnabledAttribute behavior = operation.Behaviors.Find<ReceiveContextEnabledAttribute>();
                            if (behavior == null)
                            {
                                operation.Behaviors.Add(new ReceiveContextEnabledAttribute() { ManualControl = true });
                            }
                            else
                            {
                                behavior.ManualControl = true;
                            }
                        }
                    }
                }
                return host;
            }
    ...

    Wednesday, April 9, 2014 5:51 PM

Answers

  • Apologies to all who read this and especially the Workflow team for assuming there was a bug. I reached the wrong conclusion.

    The problem was not that SendMessageChannelCache was not working, but the cache settings were too low for the stress tests I was running. Therefore I was seeing a lot of new connections being established. After I increased the cache settings the problem went away.

    When enabling ReceiveContext the throughput of the workflow service increases about 3x times on my environment and the channel cache was being saturated.

    Regards Michael

    Thursday, April 10, 2014 9:08 AM

All replies

  • Hi Michael,

    According to your codes above, it seems that your code is fine.

    foreach (OperationDescription operation in endpoint.Contract.Operations)
                        {
                            ReceiveContextEnabledAttribute behavior = operation.Behaviors.Find<ReceiveContextEnabledAttribute>();
                            if (behavior == null)
                            {
                                operation.Behaviors.Add(new ReceiveContextEnabledAttribute() { ManualControl = true });
                            }
                            else
                            {
                                behavior.ManualControl = true;
                            }
    

    Here is a sample about the usage of ReceiveContextEnabledAttribute and SendMessageChannelCache , http://www.projky.com/dotnet/4.5.1/System/ServiceModel/Activities/WorkflowServiceHost.cs.html                                    


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 10, 2014 3:23 AM
  • Apologies to all who read this and especially the Workflow team for assuming there was a bug. I reached the wrong conclusion.

    The problem was not that SendMessageChannelCache was not working, but the cache settings were too low for the stress tests I was running. Therefore I was seeing a lot of new connections being established. After I increased the cache settings the problem went away.

    When enabling ReceiveContext the throughput of the workflow service increases about 3x times on my environment and the channel cache was being saturated.

    Regards Michael

    Thursday, April 10, 2014 9:08 AM