询问者
wf4.0示例文档审批流程 运行报错

问题
-
在 路径\WF_WCF_Samples\WF\Application\DocumentApprovalProcess\CS\ApprovalManager\Program.cs中
ServiceHost sh = new ServiceHost(typeof(Microsoft.Samples.DocumentApprovalProcess.ApprovalManager.SubscriptionManager), new Uri("http://localhost:8732/Design_Time_Addresses/service/SubscriptionManager/"));
sh.Open();System.ServiceModel.Activities.WorkflowServiceHost wsh = new System.ServiceModel.Activities.WorkflowServiceHost(shservice, new Uri("http://localhost:8732/Design_TimeAddress/service/ApprovalManager"));
// Setup persistence
wsh.Description.Behaviors.Add(new SqlWorkflowInstanceStoreBehavior(ApprovalProcessDBConnectionString));
WorkflowIdleBehavior wib = new WorkflowIdleBehavior();
wib.TimeToUnload = new TimeSpan(0, 0, 2);
wsh.Description.Behaviors.Add(wib);wsh.Open(); ---报“无法初始化 InstanceStore”的错误!
全部回复
-
试一试用
host.DurableInstancingOptions.InstanceStore = new SqlWorkflowInstanceStore(connectionString);
添加Persistence Store.
This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook" -
这个在哪里加呢?我加入进去还是报同样的错误 无法初始化InstanceStore
static void Main(string[] args)
{
Activity element = new ApprovalRouteAndExecute();WorkflowService shservice = new WorkflowService
{
Name = "ApprovalManager",
ConfigurationName = "Microsoft.Samples.DocumentApprovalProcess.ApprovalManager.ApprovalManager",
Body = element
};// Cleanup old table of users from previous run
UserManager.DeleteAllUsers();ServiceHost sh = new ServiceHost(typeof(Microsoft.Samples.DocumentApprovalProcess.ApprovalManager.SubscriptionManager), new Uri("http://localhost:8732/Design_Time_Addresses/service/SubscriptionManager/"));
sh.Open();
System.ServiceModel.Activities.WorkflowServiceHost wsh = new System.ServiceModel.Activities.WorkflowServiceHost(shservice, new Uri("http://localhost:8732/Design_TimeAddress/service/ApprovalManager"));
// Setup persistence
SqlWorkflowInstanceStoreBehavior ssbh = new SqlWorkflowInstanceStoreBehavior(ApprovalProcessDBConnectionString);
ssbh.InstanceCompletionAction = InstanceCompletionAction.DeleteNothing;
wsh.Description.Behaviors.Add(ssbh);
WorkflowIdleBehavior wib = new WorkflowIdleBehavior()
{
TimeToUnload =TimeSpan.FromSeconds(0)
};
//wib.TimeToUnload = new TimeSpan(0, 0, 2);
wsh.Description.Behaviors.Add(wib);wsh.DurableInstancingOptions.InstanceStore = new SqlWorkflowInstanceStore(ApprovalProcessDBConnectionString);
wsh.Open();
Console.WriteLine("All services ready, press any key to close the services and exit.");Console.ReadLine();
wsh.Close();
sh.Close();
}
learn wf wcf wpf -
下面是完整的代码:
using System;
using System.Collections.Generic;
using System.Workflow.Activities;
using System.Activities;
using System.Workflow.Runtime;
using System.ServiceModel.Activities.Activation;
using System.ServiceModel.Activities;
using System.ServiceModel.Description;
using System.Activities.DurableInstancing;
using System.Configuration;
namespace Xhinker.WF4.MyXamlxFactory {
public class MyServiceHostFactory : System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory {
protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service,
Uri[] baseAddresses) {
WorkflowServiceHost host = base.CreateWorkflowServiceHost(service, baseAddresses);
string connectionString = ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();
host.DurableInstancingOptions.InstanceStore = new SqlWorkflowInstanceStore(connectionString);
return host;
}
private SqlWorkflowInstanceStore SetupSimplySqlPersistenceStore() {
string connectionString =
ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();
SqlWorkflowInstanceStore sqlInstanceStore =
new SqlWorkflowInstanceStore(connectionString);
sqlInstanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30);
return sqlInstanceStore;
}
}
}
MSDN Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
Microsoft Windows Workflow Foundation 4.0 Cookbook- 已建议为答案 Windie Chai [MVP]Moderator 2011年3月7日 7:24