locked
Custom Perisistence: There can only be one service of type "WorkflowPersistenceService"

    Question

  • I initially created a simple ASP.NET app to demonstrate a state machine and passing data to a workflow using a local service. It works fines. Now I am trying to play with persistence.

    I have created a custom persistence service using MySQL. I have followed the steps outlined in the SDK help. I have added the needed entries in the web.config line. Here is my Global.asax entries.

            protected void Application_Start(object sender, EventArgs e)
            {
                System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime("WorkflowRuntime");
                Application[Constants.WorkflowRuntime] = workflowRuntime;

                // attach persistence service
                MySqlPersistenceService stateservice = new MySqlPersistenceService();
                workflowRuntime.AddService(stateservice);

                workflowRuntime.StartRuntime();
            }

            protected void Application_End(object sender, EventArgs e)
            {
                System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application[Constants.WorkflowRuntime] as System.Workflow.Runtime.WorkflowRuntime;
                workflowRuntime.StopRuntime();
            }

    In my web form code behind I have the following:

                WorkflowRuntime workflowRuntime = Application[Constants.WorkflowRuntime] as WorkflowRuntime;

                // Now get a refernece to the ManualWorkflowSchedulerService
                ManualWorkflowSchedulerService scheduler = workflowRuntime.GetService<ManualWorkflowSchedulerService>();

                ExternalDataExchangeService dataService = workflowRuntime.GetService<ExternalDataExchangeService>();
                RequestService requestService = workflowRuntime.GetService<RequestService>();

                if (requestService == null)
                {
                    requestService = new RequestService();
                    dataService.AddService(requestService);
                }

                //// Attach to the WorkflowCompleted event
                workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);

                // start workflow instance
                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(RequestWorkflows));
                workflowInstance.Start();

                // Now run the workflow.  This is necessary when using the ManualWorkflowSchedulerService
                scheduler.RunWorkflow(workflowInstance.InstanceId);

    I get the following error when I attempt to execute the CreateWorkflow line.

    There can only be one service of type "WorkflowPersistenceService".

    Can anyone explain why?

    Thanks

    Bill

     

    Monday, July 31, 2006 1:05 PM

Answers

  • You are trying to add your service in both config and code.  You only need one.  I'd remove the code that is adding your service and just use the configuration. 

    Matt

    Monday, July 31, 2006 3:17 PM
  • It looks like you're adding your persistence service both in code and in the web.config.  Only add it in one place or the other.

    Thanks,

    Joel West

    MSFTE - SDE in WF runtime and hosting

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

    Monday, July 31, 2006 5:47 PM

All replies

  • Did you check your web.config file and make sure the default SQL persistence service was not configured?

    Matt

    Monday, July 31, 2006 2:33 PM
  • From what I can see I am not using the default SQL persistence. Here are my web.config entries:

     <configSections>
      <section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
     </configSections>

     <WorkflowRuntime Name="WorkflowServiceContainer">
      <Services>
       <add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
       <add type="System.Workflow.Activities.ExternalDataExchangeService, System.Workflow.Activities, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
       <add type="Common.Workflow.MySql.MySqlPersistenceService, Common.Workflow" />
      </Services>
     </WorkflowRuntime>

    MySqlPersistenceService is my custom persistence class derived from WorkflowPersistenceService per the SDK documentation.

    Thanks

    Bill

     

    Monday, July 31, 2006 3:12 PM
  • You are trying to add your service in both config and code.  You only need one.  I'd remove the code that is adding your service and just use the configuration. 

    Matt

    Monday, July 31, 2006 3:17 PM
  • It looks like you're adding your persistence service both in code and in the web.config.  Only add it in one place or the other.

    Thanks,

    Joel West

    MSFTE - SDE in WF runtime and hosting

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

    Monday, July 31, 2006 5:47 PM
  • You were right. I did  not know that adding the entry to the web.config automatically added the persistence service to the workflow.

    Thanks

    Bill

    Monday, July 31, 2006 8:34 PM