Exemple #1
0
        static void Main(string[] args)
        {
            // Create service host.
            WorkflowServiceHost host = new WorkflowServiceHost(new CountingWorkflow(), new Uri(hostBaseAddress));

            // Add service endpoint.
            host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), "");

            // Define SqlWorkflowInstanceStoreBehavior:
            //   Set interval to renew instance lock to 5 seconds.
            //   Set interval to check for runnable instances to 2 seconds.
            //   Instance Store does not keep instances after it is completed.
            //   Select exponential back-off algorithm when retrying to load a locked instance.
            //   Instance state information is compressed using the GZip compressing algorithm.
            SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(connectionString);
            instanceStoreBehavior.HostLockRenewalPeriod = new TimeSpan(0, 0, 5);
            instanceStoreBehavior.RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2);
            instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;
            instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry;
            instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip;
            host.Description.Behaviors.Add(instanceStoreBehavior);

            // Open service host.
            host.Open();

            // Create a client that sends a message to create an instance of the workflow.
            ICountingWorkflow client = ChannelFactory<ICountingWorkflow>.CreateChannel(new BasicHttpBinding(), new EndpointAddress(hostBaseAddress));
            client.start();

            Console.WriteLine("(Press [Enter] at any time to terminate host)");
            Console.ReadLine();
            host.Close();
        }
Exemple #2
0
        static void Main()
        {
            System.ServiceModel.Activities.WorkflowServiceHost myServiceHost = new System.ServiceModel.Activities.WorkflowServiceHost(new Sequence1(), new Uri("http://localhost:8080/Client"));

            //Create an endpoint in the service host to enable comunication with the Receive activity inside the Workflow.
            myServiceHost.AddServiceEndpoint("IWorkflow", new BasicHttpBinding(), "IWorkflow");

            //Set up SQL Instance Store
            string myConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=DefaultSampleStore;Integrated Security=True;Asynchronous Processing=True";
            SqlWorkflowInstanceStoreBehavior sqlWorkflowInstanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(myConnectionString);
            myServiceHost.Description.Behaviors.Add(sqlWorkflowInstanceStoreBehavior);

            //Set the TimeToUnload to 0 to force the WF to be unloaded. To have a durable delay, the WF needs to be unloaded otherwise it will be thread as an in-memory delay.
            WorkflowIdleBehavior workflowIdleBehavior = new WorkflowIdleBehavior()
            {
                TimeToUnload = TimeSpan.FromSeconds(0)
            };
            myServiceHost.Description.Behaviors.Add(workflowIdleBehavior);

            myServiceHost.Open();
            Console.WriteLine("WorkflowServiceHost started");

            //To create an instance of the Workflow, we are sending a message to the receive in the Workflow.
            IWorkflow proxy = ChannelFactory<IWorkflow>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost:8080/Client/IWorkflow"));
            proxy.Start();
            Console.WriteLine("Client started");

            Console.ReadLine();
            myServiceHost.Close();
        }
 internal SqlWorkflowInstanceStorePromotionBehavior(SqlWorkflowInstanceStoreBehavior sqlWorkflowInstanceStoreBehavior)
 {
     base.ConnectionString = sqlWorkflowInstanceStoreBehavior.ConnectionString;
     base.HostLockRenewalPeriod = sqlWorkflowInstanceStoreBehavior.HostLockRenewalPeriod;
     base.InstanceCompletionAction = sqlWorkflowInstanceStoreBehavior.InstanceCompletionAction;
     base.InstanceEncodingOption = sqlWorkflowInstanceStoreBehavior.InstanceEncodingOption;
     base.InstanceLockedExceptionAction = sqlWorkflowInstanceStoreBehavior.InstanceLockedExceptionAction;
     base.RunnableInstancesDetectionPeriod = sqlWorkflowInstanceStoreBehavior.RunnableInstancesDetectionPeriod;
 }
        public static WorkflowServiceHost CreateWorkflowServiceHost()
        {
            // add the workflow implementation and application endpoint to the host
            WorkflowService service = new WorkflowService()
            {
                Body = PurchaseOrderWorkflow.CreateBody(),

                Endpoints =
                {
                    // adds an application endpoint
                    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);

            // add the workflow management behaviors
            IServiceBehavior idleBehavior = new WorkflowIdleBehavior { TimeToUnload = TimeSpan.Zero };
            workflowServiceHost.Description.Behaviors.Add(idleBehavior);

            IServiceBehavior workflowUnhandledExceptionBehavior = new WorkflowUnhandledExceptionBehavior()
            {
                Action = WorkflowUnhandledExceptionAction.AbandonAndSuspend // this is also the default
            };
            workflowServiceHost.Description.Behaviors.Add(workflowUnhandledExceptionBehavior);

            // add the instance store
            SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior()
            {
                ConnectionString = "Server=localhost\\SQLEXPRESS;Integrated Security=true;Initial Catalog=DefaultSampleStore;"
            };
            workflowServiceHost.Description.Behaviors.Add(instanceStoreBehavior);

            // add a workflow management endpoint
            ServiceEndpoint workflowControlEndpoint = new WorkflowControlEndpoint()
            {
                Binding = new System.ServiceModel.NetNamedPipeBinding(System.ServiceModel.NetNamedPipeSecurityMode.None),
                Address = new System.ServiceModel.EndpointAddress("net.pipe://workflowInstanceControl")
            };
            workflowServiceHost.AddServiceEndpoint(workflowControlEndpoint);

            // add the tracking participant
            workflowServiceHost.WorkflowExtensions.Add(new TrackingListenerConsole());

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

            return workflowServiceHost;
        }
Exemple #5
0
        // start the service
        static void Main(string[] args)
        {
            string persistenceConnectionString = ConfigurationManager.ConnectionStrings["WorkflowPersistence"].ConnectionString;
            string baseAddr = "http://localhost:8080/Contoso/HiringRequestService";

            using (WorkflowServiceHost host = new WorkflowServiceHost(new HiringRequestProcessServiceDefinition(), new Uri(baseAddr)))
            {
                SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(persistenceConnectionString);
                instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;
                instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip;

                host.Description.Behaviors.Add(instanceStoreBehavior);
                host.Description.Behaviors.Add(new WorkflowIdleBehavior() { TimeToPersist = new TimeSpan(0) });

                host.WorkflowExtensions.Add(new HiringRequestInfoPersistenceParticipant());

                // configure the unknown message handler
                host.UnknownMessageReceived += new EventHandler<System.ServiceModel.UnknownMessageReceivedEventArgs>(Program.UnknownMessageReceive);

                // add the control endpoint
                WorkflowControlEndpoint publicEndpoint = new WorkflowControlEndpoint(
                                                                new BasicHttpBinding(),
                                                                new EndpointAddress(new Uri("http://127.0.0.1/hiringProcess")));
                host.AddServiceEndpoint(publicEndpoint);
                host.AddDefaultEndpoints();

                // start the service
                Console.WriteLine("Starting ...");

                host.Open();

                // end when the user hits enter
                Console.WriteLine("Service is waiting at: " + baseAddr);
                Console.WriteLine("Press [Enter] to exit");
                Console.ReadLine();
                host.Close();
            }
        }
        private void SetupHost()
        {
            WorkflowService service = new WorkflowService
            {
                Name = "LeadResponse",
                Body = new WorkAssignment(),
                Endpoints =
                {
                    new Endpoint
                    {
                        ServiceContractName="CreateAssignment",
                        AddressUri = new Uri("http://localhost/CreateAssignment"),
                        Binding = new BasicHttpBinding(),
                    }
                }
            };

            // Create a WorkflowServiceHost that listens for incoming messages
            _wsh = new System.ServiceModel.Activities.WorkflowServiceHost(service);

            SqlWorkflowInstanceStoreBehavior instanceStoreBehavior
                = new SqlWorkflowInstanceStoreBehavior(_connectionString);
            instanceStoreBehavior.InstanceCompletionAction
                = InstanceCompletionAction.DeleteAll;
            instanceStoreBehavior.InstanceLockedExceptionAction
                = InstanceLockedExceptionAction.AggressiveRetry;
            _wsh.Description.Behaviors.Add(instanceStoreBehavior);

            WorkflowIdleBehavior wib = new WorkflowIdleBehavior();
            wib.TimeToUnload = TimeSpan.FromMilliseconds(100);
            _wsh.Description.Behaviors.Add(wib);

            _wsh.Description.Behaviors.Add
                (new DBExtensionBehavior(_connectionString));
            _wsh.Description.Behaviors.Add
                (new PersistAssignmentBehavior(_connectionString));

            // Open the service so it will listen for messages
            _wsh.Open();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            // Create service host.
            WorkflowServiceHost host = new WorkflowServiceHost(CountingWorkflow(), new Uri(hostBaseAddress));

            // Add service endpoint.
            host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), "");

            // Define SqlWorkflowInstanceStore and assign it to host.
            SqlWorkflowInstanceStoreBehavior store = new SqlWorkflowInstanceStoreBehavior(connectionString);
            List<XName> variantProperties = new List<XName>()
            {
                xNS.GetName("Count")
            };
            store.Promote("CountStatus", variantProperties, null);

            host.Description.Behaviors.Add(store);

            host.WorkflowExtensions.Add<CounterStatus>(() => new CounterStatus());
            host.Open(); // This sample needs to be run with Admin privileges.
                         // Otherwise the channel listener is not allowed to open ports.
                         // See sample documentation for details.

            // Create a client that sends a message to create an instance of the workflow.
            ICountingWorkflow client = ChannelFactory<ICountingWorkflow>.CreateChannel(new BasicHttpBinding(), new EndpointAddress(hostBaseAddress));
            client.start();

            Console.WriteLine("(Press [Enter] at any time to terminate host)");
            Console.ReadLine();
            host.Close();
        }
        protected internal override object CreateBehavior()
        {
            bool useDefaultConnectionStringName = false;

            if (string.IsNullOrEmpty(this.ConnectionString) &&
                string.IsNullOrEmpty(this.ConnectionStringName))
            {
                useDefaultConnectionStringName = true;
            }

            if (!string.IsNullOrEmpty(this.ConnectionString) &&
                !string.IsNullOrEmpty(this.ConnectionStringName))
            {
                throw FxTrace.Exception.AsError(new InstancePersistenceException(SR.CannotSpecifyBothConnectionStringAndName));
            }

            string connectionStringToUse;
            if (!string.IsNullOrEmpty(this.ConnectionStringName) || useDefaultConnectionStringName)
            {
                string connectionStringNameToUse = useDefaultConnectionStringName ? defaultConnectionStringName : this.ConnectionStringName;
                ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[connectionStringNameToUse];

                if (settings == null)
                {
                    if (useDefaultConnectionStringName)
                    {
                        throw FxTrace.Exception.AsError(new InstancePersistenceException(SR.MustSpecifyConnectionStringOrName));
                    }

                    throw FxTrace.Exception.Argument(connectionStringName, SR.ConnectionStringNameWrong(this.ConnectionStringName));
                }

                connectionStringToUse = settings.ConnectionString;
            }
            else
            {
                connectionStringToUse = this.ConnectionString;
            }

            SqlWorkflowInstanceStoreBehavior sqlWorkflowInstanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior
            {
                ConnectionString = connectionStringToUse,
                HostLockRenewalPeriod = this.HostLockRenewalPeriod,
                InstanceEncodingOption = this.InstanceEncodingOption,
                InstanceCompletionAction = this.InstanceCompletionAction,
                InstanceLockedExceptionAction = this.InstanceLockedExceptionAction,
                RunnableInstancesDetectionPeriod = this.RunnableInstancesDetectionPeriod,
                MaxConnectionRetries = this.MaxConnectionRetries
            };

            return sqlWorkflowInstanceStoreBehavior;
        }