Persistance - avoid serializing a variable RRS feed

  • Question

  • Hi,


    We have a situation where we have a long running workflow and we have a variable within our workflow that contains a complex object. We have out own tables for storing the complex object which we persist to prior to each bookmark. However with the standard functionality the object is also stored to the standard SQL persistance tables in a binary serialized format. This causes us some issues as for this to work the object needs to be serializable and this means that we end up storing the object twice - once in our tables and again in a serialized format in the Workflow Persistance store.

    What we we would like to do is to only store this to our tables and not persist this to the workflow persistance store. When the workflow resumes we will repopulate the variable with the object that we load from our own tables.


    Is there an easy way of doing this using the framework? If not, how would we go about doing this? I assume that we could just set the variable value to be NULL prior to the bookmark and then repopulate the variable after the bookmark has resumed? And if we were to do this, could this lead to any potential issues?

    There was a similar post to this (http://social.msdn.microsoft.com/Forums/en/wfprerelease/thread/96f345e7-1281-4eb5-82ac-624ec1432af6) but it didn't seem to come to a conclustion.

    Any help would be appreciated.


    Monday, June 20, 2011 5:45 AM

All replies

  • Hi Matthew,

    Have you explore PersistenceIOParticipant class for custom persistence.

    You can persist your custom object to your database (other than instance store) by overriding BeginOnSave method and can retrieve it by overriding BeginOnLoad method. BeginOnLoad will be invoked once your workflow resume and BeginOnSave invokes when your workflow is unloaded from the memory.

    Hope this will solve your problem.


    Tuesday, June 21, 2011 6:58 AM
  • Thanks Nauman, it looks like PersistenceIOParticipant is the "hook" we are looking for.

    However, it seems we cannot get at workflow Variables from BeginOnLoad or BeginOnSave.

    By digging through in the debugger we can see they are in there somewhere but (perhaps because our workflow definitions are dynamically loaded from XAML) they are not exposed to the API. We can get at the Arguments but not the Variables.

    Is there a way to do it?


    Alan (Matthew's colleague)


    Wednesday, June 22, 2011 2:25 AM
  • Nauman,


    Thanks for the reply. The PerisistenceIOParticipant seems to be where we should be putting this, but we are struggling to understand how to do this. Do you have a code example of how we could do this?


    The key aspects for us are

    • Able to get access to a variable on store so that we can persist to our own tables
    • Able to stop the variable from being persisted to the standard workflow SQL persistence store - as the object isn't serializable
    • Able to reload the variable from our tables when the workflow is restarted





    Monday, June 27, 2011 3:57 AM