public void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     if (serviceHostBase is WorkflowServiceHost)
     {
         foreach (ChannelDispatcherBase base2 in serviceHostBase.ChannelDispatchers)
         {
             ChannelDispatcher dispatcher = base2 as ChannelDispatcher;
             if (dispatcher != null)
             {
                 foreach (EndpointDispatcher dispatcher2 in dispatcher.Endpoints)
                 {
                     if (WorkflowServiceBehavior.IsWorkflowEndpoint(dispatcher2))
                     {
                         dispatcher2.DispatchRuntime.PreserveMessage = true;
                         foreach (DispatchOperation operation in dispatcher2.DispatchRuntime.Operations)
                         {
                             operation.BufferedReceiveEnabled = true;
                         }
                     }
                 }
             }
         }
         serviceHostBase.Extensions.Add(new BufferedReceiveManager(this.MaxPendingMessagesPerChannel));
     }
 }
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            if (serviceHostBase is WorkflowServiceHost)
            {
                foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
                {
                    ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                    if (channelDispatcher != null)
                    {
                        foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                        {
                            if (WorkflowServiceBehavior.IsWorkflowEndpoint(endpointDispatcher))
                            {
                                // We need all incoming messages to be copyable
                                endpointDispatcher.DispatchRuntime.PreserveMessage = true;

                                // Enable BufferedReceive processing for each operation
                                foreach (DispatchOperation dispatchOperation in endpointDispatcher.DispatchRuntime.Operations)
                                {
                                    dispatchOperation.BufferedReceiveEnabled = true;
                                }
                            }
                        }
                    }
                }

                serviceHostBase.Extensions.Add(new BufferedReceiveManager(this.MaxPendingMessagesPerChannel));
            }
        }