views:

1762

answers:

3

Hallo everybody,

I'm dealing with a pretty strange situation here. I have developed a State Machine Workflow and it worked just fine until today. Now, the Sql Workflow Persistence Service does not save the workflow state. There is no any exception, just it does not save the state. The flow is going normally to the Event Driven activity which is, by following this article link, one of the conditions when workflow state has to be saved (what it has been doing just fine before).

The configuration of Sql Workflow Persistence Service look like this:

     <workflowRuntime name="WorkfolwServiceHostRuntime" validateOnCreate="true"
        enablePerformanceCounters="true">
        <services>
          <add 
            type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, 
                System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, 
                PublicKeyToken=31bf3856ad364e35" 
             connectionString="Data Source=svr; 
               Initial Catalog=WorkflowPersistence; user id=User;password=Pass; 
               Trusted_Connection=False" LoadIntervalSeconds="1" 
               UnLoadOnIdle="true"/>

        </services>
      </workflowRuntime>

Maybe the problem is because there is one more application that hosts workflow runtime and uses the same workflow persistence database. I couldn't find any information if this is allowed or not.

I cant see any other reason why is this happening, so I will appreciate any suggestion.

Thanks

A: 

OK, finally, I found out what was the problem. In the first post I wrote that at first everything worked just as charmed but after some little changes,that should not influence the persisting of the workflow, Sql Workflow Persistence Service was not able to save the state in database.

What I didn't mention the I exposed workflow as a WCF Service, and it turns out that crucial to solve this problem. I apologize to everybody that tried to solve this whit lack of information.

I used the Receive Activity which I pointed to the method WCF Service contract. That method had a return value of complex type:

[DataContract]
public class ServiceCallInfo
{
    int code;
    [DataMember]
    public int Code
    {
        get { return code; }
        set { code = value; }
    }
    string message;

    [DataMember]
    public string Message
    {
        get { return message; }
        set { message = value; }
    }
}

I binded that return value to the new property of the workflow.

public static DependencyProperty ReturnInfoProperty = DependencyProperty.Register("ReturnInfo", typeof(my.mynamespace.ServiceCallInfo), typeof(my.mynamespace.StandardContractingWorkflow));

    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    [BrowsableAttribute(true)]
    [CategoryAttribute("Parameters")]
    public my.mynamespace.ServiceCallInfo ReturnInfo
    {
        get
        {
            return ((my.mynamespace.ServiceCallInfo)(base.GetValue(my.mynamespace.ReturnInfoProperty)));
        }
        set
        {
            base.SetValue(my.mynamespace.ReturnInfoProperty, value);
        }
    }

If I only instantiate this property somewhere in the code of the workflow, Workflow Runtime fails to save the state, and if I don't do that state is saved properly! I assume that, for some reason, Workflow Runtime was not able to serialize (or whatever it does to save the state using Sql Workflow Persistence Service) workflow state because of this property.

Maybe it's because of definition of ServiceCallInfo class, maybe it's something else... I hope that someone with more knowledge and experience will be able to say what were the real reasons...

However, this problem is solved.

Misha N.
+2  A: 

Normally the workflow is persisted when it becomes idle. How soon it gets persisted also depends upon factors such as the polling interval ( which you would have provided while creating the SQLPersistenceService and attaching it to the runtime.) Also Everything that the workflow uses, esp. The ExternalDataEvent args and the events should be marked as Serializable.

Regarding handling Exceptions, you should add FaultHandlersActivity to your workflow, and the exception that is caught, will be saved in the Fault property that gets exposed along with the FaultHandlersActivity.

Hope that's helpful.

I marked the ServiceCallInfo as Serializable and it works just fine. Obviously it's not enough to mark the class with DataContract attribute, the Serializable attribute is necesarry as well.Thanks Socrates, this is a real solution to the problem. Regards
Misha N.
A: 

Acctually you don't need to remove those variables, you just need put NonSerialized attribute on its