Esempio n. 1
0
        public static WorkflowServiceHost CreateWorkflowServiceHost()
        {
            WorkflowService service = new WorkflowService()
            {
                Body = PurchaseOrderWorkflow.CreateBody(),

                Endpoints =
                {
                    new System.ServiceModel.Endpoint
                    {
                        Binding             = new System.ServiceModel.NetMsmqBinding("NetMsmqBindingTx"),
                        AddressUri          = new Uri("net.msmq://localhost/private/ReceiveTx"),
                        ServiceContractName = XName.Get(PurchaseOrderWorkflow.poContractDescription.Name)
                    }
                }
            };

            WorkflowServiceHost workflowServiceHost = new WorkflowServiceHost(service);

            IServiceBehavior idleBehavior = new WorkflowIdleBehavior {
                TimeToUnload = TimeSpan.Zero
            };

            workflowServiceHost.Description.Behaviors.Add(idleBehavior);

            IServiceBehavior workflowUnhandledExceptionBehavior = new WorkflowUnhandledExceptionBehavior()
            {
                Action = WorkflowUnhandledExceptionAction.AbandonAndSuspend
            };

            workflowServiceHost.Description.Behaviors.Add(workflowUnhandledExceptionBehavior);

            SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior()
            {
                ConnectionString = "Server=localhost\\SQLEXPRESS;Integrated Security=true;Initial Catalog=DefaultSampleStore;"
            };

            workflowServiceHost.Description.Behaviors.Add(instanceStoreBehavior);

            ServiceEndpoint workflowControlEndpoint = new WorkflowControlEndpoint()
            {
                Binding = new System.ServiceModel.NetNamedPipeBinding(System.ServiceModel.NetNamedPipeSecurityMode.None),
                Address = new System.ServiceModel.EndpointAddress("net.pipe://workflowInstanceControl")
            };

            workflowServiceHost.AddServiceEndpoint(workflowControlEndpoint);
            workflowServiceHost.WorkflowExtensions.Add(new TrackingListenerConsole());

            foreach (ServiceEndpoint ep in workflowServiceHost.Description.Endpoints)
            {
                Console.WriteLine(ep.Address);
            }

            return(workflowServiceHost);
        }
        static WorkflowServiceHost CreateHost(Activity activity, System.ServiceModel.Channels.Binding binding, EndpointAddress endpointAddress)
        {
            var host = new WorkflowServiceHost(activity);

            {
                SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior("Server =localhost; Initial Catalog = WF; Integrated Security = SSPI")
                {
                    HostLockRenewalPeriod            = new TimeSpan(0, 0, 5),
                    RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2),
                    InstanceCompletionAction         = InstanceCompletionAction.DeleteAll,
                    InstanceLockedExceptionAction    = InstanceLockedExceptionAction.AggressiveRetry,
                    InstanceEncodingOption           = InstanceEncodingOption.GZip,
                    MaxConnectionRetries             = 3,
                };
                host.Description.Behaviors.Add(instanceStoreBehavior);

                //Make sure this is cleared defined, otherwise the bookmark is not really saved in DB though a new record is created. https://msdn.microsoft.com/en-us/library/ff729670%28v=vs.110%29.aspx
                WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior()
                {
                    TimeToPersist = TimeSpan.Zero,
                    TimeToUnload  = TimeSpan.Zero,
                };
                host.Description.Behaviors.Add(idleBehavior);

                WorkflowUnhandledExceptionBehavior unhandledExceptionBehavior = new WorkflowUnhandledExceptionBehavior()
                {
                    Action = WorkflowUnhandledExceptionAction.Terminate,
                };
                host.Description.Behaviors.Add(unhandledExceptionBehavior);

                ResumeBookmarkEndpoint endpoint = new ResumeBookmarkEndpoint(binding, endpointAddress);
                host.AddServiceEndpoint(endpoint);

                var debugBehavior = host.Description.Behaviors.Find <ServiceDebugBehavior>();
                if (debugBehavior == null)
                {
                    host.Description.Behaviors.Add(new ServiceDebugBehavior()
                    {
                        IncludeExceptionDetailInFaults = true
                    });
                }
                else
                {
                    debugBehavior.IncludeExceptionDetailInFaults = true;
                }
            }

            return(host);
        }