locked
Persistence of Declarative Service RRS feed

  • Question

  • I am new to Workflows. Can anybody guide me on how to setup persistence with Declarative Workflow Services. I will be hosting these services on IIS. My Declarative service is a long running process so I want that whenever it goes idle it should persist in SqlDatabase.
    Monday, September 7, 2009 6:25 AM

Answers

  • Hi Suchi,
    There are essentially two topice here in your questions. The first is persisting a workflow service. The second is having the client make subsequent calls to the WF service and contact the same instance each time. This is correlation. Since you have persistence working I'll direct my comments to correlation only.

    Correlation is the mechanism to identify what service instance the message is indented for. So the first receive must initialize the correlation data and all subsequent receives use the same data to identify that service instance. When the first receive is called and the service instance is created it will create a correlation handle for that particular instance. How this handle gets created is dependent on what type of correlation the service is going to use. There are two types - context and content. With context correlation the service is going to send back data to the client to use in all further communication with this service instance.. In the case of BasicHttpContextBinding, it is a cookie, but for the other context bindings it is actually a well-defined ContextExchange header in the message. Context correlation requires an initial receive send pair. The send is require since the service has to send the correlation data back to the client for all future receives. With context correlation the workflow runtime does most of the work for you as it sets up the cookie or the message header.

    If the service uses content correlation you have to provide the data to look for in the incoming message...like a product ID - something that you know is there everytime. You don't provide the actual value...you just define the type. Also, the service will have to have a correlation query initialized. In Beta1 you do this manually using Correlation Queries. In Beta 2 you can do this manually with the Initialize Correlation activity or you can setup the receive activity to do it for you by configuring the parameters for the correlation query in the designer. Regardless how it is initialized this query is going to be based on content in the message that is sent by the client with all subsequent receives. The correlation query itself can be different (and often is) for each activity.  The important thing is actually the data that the query pulls out; as long as that data is the same, then the correlation will work as planned.  For example...Imagine two Receives, one which receives an integer, and one which receives a complex type (Foo) which has an integer property in it (Foo.Int); these correlation queries will be different, but the data extracted should be the same in order for those two Receives to be correlated.

    The samples are a great place to start in seeing how correlation is configured. Also check out the VS 2010 Training Kit as it has a hands-on lab around WF Services and discusses configuring correlation as well. The Training Kit is available at http://code.msdn.microsoft.com/wcfwf4.

    Hope this helps clarify things for you.

    -Amy

    • Marked as answer by Sneha Gupta Tuesday, September 29, 2009 4:24 AM
    Tuesday, September 22, 2009 6:48 PM

All replies

  • I am able to achieve Persistence by using Persist activity and by ading persistenceProvider through web.config but now what i want is when client calls the service first time, an instance should be created and after processing some business logic it should persist in memotry . But subsequently when the same client calls the service, it should use the existing instance and not create  a new one. How will i achieve this or Is my approach wrong.
    Monday, September 7, 2009 10:46 AM
  • You might need persistence, but you definitely need correlation so your subsequenct messages get sent to the correct workflow instance.  Have a look at the SDK samples [1]: specifically, the WF\Scenario\Services\CorrelatedCalculator sample provides a pretty good introduction.  Also, Aaron has a good introduction to the topic in his whitepaper on WCF 4 [2]. 

    Matt

    [1] http://www.microsoft.com/downloads/details.aspx?FamilyID=5aca0622-d87d-4cc9-a22c-0d58205a56b4&displaylang=en
    [2] http://msdn.microsoft.com/en-us/library/ee354381.aspx


    Check out Pluralsight On Demand! http://www.pluralsight.com/main/olt/
    Tuesday, September 8, 2009 6:23 PM
  • Hi Suchi,
    There are essentially two topice here in your questions. The first is persisting a workflow service. The second is having the client make subsequent calls to the WF service and contact the same instance each time. This is correlation. Since you have persistence working I'll direct my comments to correlation only.

    Correlation is the mechanism to identify what service instance the message is indented for. So the first receive must initialize the correlation data and all subsequent receives use the same data to identify that service instance. When the first receive is called and the service instance is created it will create a correlation handle for that particular instance. How this handle gets created is dependent on what type of correlation the service is going to use. There are two types - context and content. With context correlation the service is going to send back data to the client to use in all further communication with this service instance.. In the case of BasicHttpContextBinding, it is a cookie, but for the other context bindings it is actually a well-defined ContextExchange header in the message. Context correlation requires an initial receive send pair. The send is require since the service has to send the correlation data back to the client for all future receives. With context correlation the workflow runtime does most of the work for you as it sets up the cookie or the message header.

    If the service uses content correlation you have to provide the data to look for in the incoming message...like a product ID - something that you know is there everytime. You don't provide the actual value...you just define the type. Also, the service will have to have a correlation query initialized. In Beta1 you do this manually using Correlation Queries. In Beta 2 you can do this manually with the Initialize Correlation activity or you can setup the receive activity to do it for you by configuring the parameters for the correlation query in the designer. Regardless how it is initialized this query is going to be based on content in the message that is sent by the client with all subsequent receives. The correlation query itself can be different (and often is) for each activity.  The important thing is actually the data that the query pulls out; as long as that data is the same, then the correlation will work as planned.  For example...Imagine two Receives, one which receives an integer, and one which receives a complex type (Foo) which has an integer property in it (Foo.Int); these correlation queries will be different, but the data extracted should be the same in order for those two Receives to be correlated.

    The samples are a great place to start in seeing how correlation is configured. Also check out the VS 2010 Training Kit as it has a hands-on lab around WF Services and discusses configuring correlation as well. The Training Kit is available at http://code.msdn.microsoft.com/wcfwf4.

    Hope this helps clarify things for you.

    -Amy

    • Marked as answer by Sneha Gupta Tuesday, September 29, 2009 4:24 AM
    Tuesday, September 22, 2009 6:48 PM
  • Hi Amy,

    Correlation is working now fine in my service. When i use Persist activity , the runtime persists the instance in the memory but also loads and resumes the instance also at the same time. What i want is when user provides some input data, then the instance should be resumed. I can achieve this using Bookmarks and hosting through WorkflowServiceHost. But my doubt is how to achieve it by hosting services in IIS. I have not seen any sample in which persistence is done for services hosted in IIS. Could you provide me with some help?

    suchi
    Tuesday, September 29, 2009 4:29 AM
  • Hi,

    I have the same problem too.  But I'm trying to use the declarative flowchart service in asp.net.  I don't know how to get back the WorkflowInstance nor using the WorkflowServiceHost.  I also want to persist the workflow.  Does anyone have any guide on this?  Thanks.

    yui
    Wednesday, October 14, 2009 3:07 AM