Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to get Persistence Participant Promotion to work with a xamlx service in WF4
    primarykey
    data
    text
    <p>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.</p> <p>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?</p> <p>So my question here is does anyone have a real working example of how to implement a persistence participant? </p> <p>I tried a few different takes on this</p> <ul> <li>Andrew Zhu's here <a href="http://xhinker.com/post/WF4Promote-persistence-Data.aspx" rel="nofollow">http://xhinker.com/post/WF4Promote-persistence-Data.aspx</a></li> <li>Microsoft Samples</li> </ul> <p>But I just cannot seem to get this to work.</p> <p><strong>Just FYI-This code works when I changed the xnamespaces to match. Thanks to Maurice</strong></p> <p>WorkflowServiceHost Code:</p> <pre><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&lt;XName&gt; variantProperties = new List&lt;XName&gt;() { 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&lt;DocumentStatusExtension&gt;(()=&gt;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; } </code></pre> <p>DocumentStatusExtension Code:</p> <pre><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&lt;XName, object&gt; readWriteValues, out IDictionary&lt;XName, object&gt; writeOnlyValues) { readWriteValues = new Dictionary&lt;XName, object&gt;(); 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&lt;XName, object&gt; MapValues(IDictionary&lt;XName, object&gt; readWriteValues, IDictionary&lt;XName, object&gt; writeOnlyValues) { return base.MapValues(readWriteValues, writeOnlyValues); } </code></pre> <p>UpdateExtension Code:</p> <pre><code>public sealed class UpdateExtension : CodeActivity { // Define an activity input argument of type string public InArgument&lt;string&gt; Text { get; set; } // If your activity returns a value, derive from CodeActivity&lt;TResult&gt; // 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&lt;DocumentStatusExtension&gt;().DocumentId = Guid.NewGuid().ToString(); context.GetExtension&lt;DocumentStatusExtension&gt;().UserName = "John Smith"; context.GetExtension&lt;DocumentStatusExtension&gt;().ApprovalStatus = "Approved"; context.GetExtension&lt;DocumentStatusExtension&gt;().LastUpdateTime = DateTime.Now; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload