locked
Workflow as Webservice Persistence in .NET4 RRS feed

  • Question

  • Hello,

    I'm currently working under VS2010, framework .NET4.

    I have a Stateful Workflow considered as a webservice (that means plenty of "Receive" and "Send" in this workflow) that i'd like to persist through a database. Unfortunately, SQL Server won't do because it will require too much conditions for the clients.

    So I'd like to persist in another way : Oracle DB or even XML files would do.

    First I thought : "Alright, there's a 'persistenceProvider' xml tag in web.config, let's use it". So i tried to get inspired through "SqlPersistenceProviderFactory" and build my own class.

    And I configured my web.config this way :

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    ...
      <system.serviceModel>
       <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <persistenceProvider type="CarInspiredWF_for_WS_persisted.TestPPF, CarInspiredWF_for_WS_persisted, Version=4.0.0.0"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>

    But when launching WCF Test Client, an error pops :

    System.ServiceModel.Activities.WorkflowServiceHost is incompatible with System.ServiceModel.Persistence.PersistenceProviderBehavior.
    The PersistenceProviderBehavior or derived class, such as SqlPersistenceProviderBehavior, should be removed.
    To enable persistence with WorkflowServiceHost, a behavior which installs a System.Runtime.DurableInstancing.InstanceStore should be used instead, such as SqlInstanceStoreBehavior.

     

    Ok ... then let's use the 'official' persistence that exists, like the XML persistence provided as example by Microsoft.

    But here's another type of error !

    Unable to cast object of type 'CarInspiredWF_for_WS_persisted.XmlWorkflowInstanceStore' to type 'System.ServiceModel.Persistence.PersistenceProviderFactory'.

    What the heck ?!?

     

    Am I missing something to do this right or is this a vicious circle ?

     

    Oh, and I'd like to add that i do NOT want a local-hosted solution, as getting a program with lot of lines and using "WorkflowHost" ...
    I'd really like just to tell the web.config my type of webservice persistence, and then consume the webservice through another program that will be the real running program.

     

    So far I haven't seen any pertinent documentation ... but I might be blind and just missing an obvious fact !

    Is there any way to do this ?

     

    Many thanks for any help !

    Friday, May 27, 2011 10:36 AM

Answers

  • persistenceProvider is a WF v1 service behavior.

    To chain in a custom InstanceStore for WF v4 service host, you will need to implement your own version of: "SqlWorkflowInstanceStoreElement" (for XML configuration purposes) and "SqlWorkflowInstanceStoreBehavior" (for creating the custom InstanceStore).

    You may want to check the SqlTracking WF sample in: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=35ec8682-d5fd-4bc3-a51a-d8ad115a8792&displaylang=en

    The tracking sample demonstrates how to chain into the WCF pipeline with a SqlTrackingExtensionElement and SqlTrackingBehavior. Although it seems off topic, the mechansim is very similar here.

    Best Regards,

    Leo

    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by tjafaas Wednesday, June 1, 2011 10:27 AM
    Monday, May 30, 2011 2:37 PM

All replies

  • persistenceProvider is a WF v1 service behavior.

    To chain in a custom InstanceStore for WF v4 service host, you will need to implement your own version of: "SqlWorkflowInstanceStoreElement" (for XML configuration purposes) and "SqlWorkflowInstanceStoreBehavior" (for creating the custom InstanceStore).

    You may want to check the SqlTracking WF sample in: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=35ec8682-d5fd-4bc3-a51a-d8ad115a8792&displaylang=en

    The tracking sample demonstrates how to chain into the WCF pipeline with a SqlTrackingExtensionElement and SqlTrackingBehavior. Although it seems off topic, the mechansim is very similar here.

    Best Regards,

    Leo

    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by tjafaas Wednesday, June 1, 2011 10:27 AM
    Monday, May 30, 2011 2:37 PM
  • Thanks for the answer, it is what I was looking for.

     

    Allow me however to continue the thread : I've managed to adapt all the necessary classes (for XML persistence so far), but I have trouble seeing why the starting webservice call begins with loading the new workflow. Since there is no file with this new Guid, and that an empty WF cannot be returned, I don't see how to dodge this error.

     

    I do have set the property "CanCreateInstance" of the starting "Receive" to "true".

    Wednesday, June 1, 2011 10:27 AM
  • The LoadWorkflowCommand has a AcceptUninitializedInstance property. When this property is true, it means loading an uninitialized instance.

    When the instanceId has not persisted the InstanceStore before, the InstanceStore can create a new record in its stoage. For example, for Sql workflow instance store, it can create a new record in the InstanceTable.

    The store then calls InstancePersistenceContext.LoadedInstance with InstanceState.Uninitialized (http://msdn.microsoft.com/zh-cn/library/system.runtime.durableinstancing.instancestate.aspx).

     

    The XmlWorkflowInstanceStore is a simplified sample demonstrating the basic concept of persistence store. It does not take care of instance management, lock, instance metadata, etc. You may want to check:

    You may want to check the MemoryStore sample at: http://wf.codeplex.com/wikipage?title=Microsoft.Activities.UnitTesting%20Overview&referringTitle=Documentation

    Best Regards,

    Leo

    This posting is provided "AS IS" with no warranties, and confers no rights.


    • Edited by Leo.Chen Friday, June 3, 2011 5:10 PM Add MemoryStore sample
    Friday, June 3, 2011 3:15 PM