Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4257340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:28:38+00:00 2026-05-21T05:28:38+00:00

I have implemented workflow persistence participant promotion, just as it shown here on Microsoft’s

  • 0

I have implemented workflow persistence participant promotion, just as it shown here on Microsoft’s website:http://msdn.microsoft.com/en-us/library/ee364726%28VS.100%29.aspx and while everything seems like everything works. I do not see the data saving to the database when I query? I think I am missing a step or microsoft missed something.

I am using a workflow application .xamlx service and I have overridden the WorkflowServiceHost. This all seems to be working fine, So I am not sure where the problem can be?

So my question here is does anyone have a real working example of how to implement a persistence participant?

I tried a few different takes on this

  • Andrew Zhu’s here http://xhinker.com/post/WF4Promote-persistence-Data.aspx
  • Microsoft Samples

But I just cannot seem to get this to work.

Just FYI-This code works when I changed the xnamespaces to match. Thanks to Maurice

WorkflowServiceHost Code:

public class ServiceHostFactory :WorkflowServiceHostFactory
{
    private static readonly string m_connectionString =
            "Data Source=localhost;Initial Catalog=WorkflowInstanceStore;Integrated Security=True";

    protected override WorkflowServiceHost CreateWorkflowServiceHost(Activity activity, Uri[] baseAddresses)
    {

        return base.CreateWorkflowServiceHost(activity, baseAddresses);

    }

    protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses)
    {

        WorkflowServiceHost host = base.CreateWorkflowServiceHost(service, baseAddresses);
        host.DurableInstancingOptions.InstanceStore = SetupInstanceStore();

        SqlWorkflowInstanceStoreBehavior sqlWorkflowInstanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(m_connectionString);
        XNamespace xNS = XNamespace.Get("http://contoso.com/DocumentStatus");
        List<XName> variantProperties = new List<XName>() 
        { 
           xNS.GetName("UserName"), 
           xNS.GetName("ApprovalStatus"), 
           xNS.GetName("DocumentId"), 
           xNS.GetName("LastModifiedTime") 
        };
        sqlWorkflowInstanceStoreBehavior.Promote("DocumentStatus", variantProperties, null);
        host.Description.Behaviors.Add(sqlWorkflowInstanceStoreBehavior);

        //Add persistence extension here:
        host.WorkflowExtensions.Add<DocumentStatusExtension>(()=>new DocumentStatusExtension());;
        host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });            

        // Handle the UnknownMessageReceived event.
        host.UnknownMessageReceived += delegate(object sender, UnknownMessageReceivedEventArgs e)
        {
            Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Unknow Message Recieved:{0}", e.Message));
        };


        return host;
    }

    private static SqlWorkflowInstanceStore SetupInstanceStore()
    {


        SqlWorkflowInstanceStore sqlWorkflowInstanceStore = new SqlWorkflowInstanceStore(m_connectionString)
        {
            InstanceCompletionAction = InstanceCompletionAction.DeleteAll,
            InstanceLockedExceptionAction = InstanceLockedExceptionAction.BasicRetry,
            HostLockRenewalPeriod = System.TimeSpan.Parse("00:00:05")
        };
        InstanceHandle handle = sqlWorkflowInstanceStore.CreateInstanceHandle();



        //InstanceHandle handle = sqlWorkflowInstanceStore.CreateInstanceHandle();
        //InstanceView view = sqlWorkflowInstanceStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
        //handle.Free();
        //sqlWorkflowInstanceStore.DefaultInstanceOwner = view.InstanceOwner;

        return sqlWorkflowInstanceStore;
    }

DocumentStatusExtension Code:

        public string DocumentId;
    public string ApprovalStatus;
    public string UserName;
    public DateTime LastUpdateTime;

    private XNamespace xNS = XNamespace.Get("http://contoso.com/");

    protected override void CollectValues(out IDictionary<XName, object> readWriteValues, out IDictionary<XName, object> writeOnlyValues)
    {
        readWriteValues = new Dictionary<XName, object>();
        readWriteValues.Add(xNS.GetName("UserName"), this.UserName);
        readWriteValues.Add(xNS.GetName("ApprovalStatus"), this.ApprovalStatus);
        readWriteValues.Add(xNS.GetName("DocumentId"), this.DocumentId);
        readWriteValues.Add(xNS.GetName("LastModifiedTime"), this.LastUpdateTime);

        writeOnlyValues = null;
    }

    protected override IDictionary<XName, object> MapValues(IDictionary<XName, object> readWriteValues, IDictionary<XName, object> writeOnlyValues)
    {
        return base.MapValues(readWriteValues, writeOnlyValues);
    }

UpdateExtension Code:

public sealed class UpdateExtension : CodeActivity
{
    // Define an activity input argument of type string
    public InArgument<string> Text { get; set; }

    // If your activity returns a value, derive from CodeActivity<TResult>
    // and return the value from the Execute method.
    protected override void Execute(CodeActivityContext context)
    {
        // Obtain the runtime value of the Text input argument
        context.GetExtension<DocumentStatusExtension>().DocumentId = Guid.NewGuid().ToString();
        context.GetExtension<DocumentStatusExtension>().UserName = "John Smith";
        context.GetExtension<DocumentStatusExtension>().ApprovalStatus = "Approved";
        context.GetExtension<DocumentStatusExtension>().LastUpdateTime = DateTime.Now;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:28:39+00:00Added an answer on May 21, 2026 at 5:28 am

    I have them working, unfortunately no sample code I can share just now. A PersistenceParticipant can be a bit tricky to setup with all the XNames involved that have to match up. Additionally there is a bug with using boolean values that stops the whole process without a warning so make sure you avoid booleans.

    Update:
    You are using different XML namespaces in your code. The CreateWorkflowServiceHost() uses http://contoso.com/DocumentStatus to define the property promotion and the CollectValues() uses http://contoso.com/ as the XML namespace of the values collected. Both should be the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a python webserver. Each http request spawns a new thread. I
I have a one time password system implemented for my website using RFC 4226
I have implemented what I thought was a pretty decent representation of MVC in
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have implemented a SAX parser in Java by extending the default handler. The
I have implemented VirtualPathProvider class so I can keep all my views in the
I have implemented tracing based on System.Diagnostics. I am also using a System.Diagnostics.TextWriterTraceListener, and
We have implemented a popup window as a modal dialog using the IE method:
I have implemented authentication systems for webapps several times over the years, but before
I have implemented a linked list as a self-referencing database table: CREATE TABLE LinkedList(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.