Click here to Skip to main content
15,898,134 members
Articles / Programming Languages / C#

WF 4 Persistence, Tracking, and Bookmarks: A Practical Approach

Rate me:
Please Sign up or sign in to vote.
4.73/5 (31 votes)
21 Aug 2010CPOL17 min read 142.5K   8.5K   62  
Shows practical examples about WF 4 Persistence, Tracking, and Bookmarks.
using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;
using System.ServiceModel.Activities;
using System.ServiceModel.Description;
using System.ServiceModel;
using System.Activities.DurableInstancing;
using System.ServiceModel.Activities.Description;

namespace TestWF2
{

    class Program
    {
        static void Main(string[] args)
        {
            //WorkflowInvoker.Invoke(new Workflow1());

            string baseAddress = "http://localhost:8089/TestWF";

            using (WorkflowServiceHost host =
            new WorkflowServiceHost(new Workflow1(), new Uri(baseAddress)))
            {
                host.Description.Behaviors.Add(new
                ServiceMetadataBehavior() { HttpGetEnabled = true });


                host.AddServiceEndpoint("IService", new BasicHttpBinding(), baseAddress);

                //control endpoint
                WorkflowControlEndpoint controlEndpoint =
new WorkflowControlEndpoint(
new BasicHttpBinding(),
new EndpointAddress(new Uri(baseAddress) + "/wce")
);
                host.AddServiceEndpoint(controlEndpoint);

                //

                SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"Data Source=.\SQL2008;Initial Catalog=SqlWorkflowInstanceStore;Integrated Security=True");
                host.DurableInstancingOptions.InstanceStore = instanceStore;

                host.Description.Behaviors.Add(new WorkflowIdleBehavior()
                {
                    TimeToPersist = TimeSpan.FromSeconds(5),
                    TimeToUnload = TimeSpan.FromSeconds(20)
                });

                host.Open();
                Console.WriteLine("Car rental service listening at: " +
                baseAddress);
                Console.WriteLine("Press ENTER to exit");
                Console.ReadLine();
            }

        }
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Lebanon Lebanon

Comments and Discussions