static void Main(string[] args) { System.ServiceModel.Activities.WorkflowServiceHost host = null; try { waitEvent = new AutoResetEvent(false); string baseAddr = "net.pipe://localhost/GuessingGame"; host = new System.ServiceModel.Activities.WorkflowServiceHost( new GuessingGame35Interop(), new Uri(baseAddr)); System.Workflow.Activities.ExternalDataExchangeService des = new System.Workflow.Activities.ExternalDataExchangeService(); ggService = new GuessingGameService(); ggService.MessageReceived += new EventHandler <MessageReceivedEventArgs>( Service_MessageReceived); des.AddService(ggService); WorkflowRuntimeEndpoint endpoint = new WorkflowRuntimeEndpoint(); endpoint.AddService(des); host.AddServiceEndpoint(endpoint); host.AddDefaultEndpoints(); ////configure persistence //string connectionString = ConfigurationManager.ConnectionStrings // ["InstanceStore"].ConnectionString; //SqlWorkflowInstanceStoreBehavior storeBehavior = // new SqlWorkflowInstanceStoreBehavior(connectionString); //host.Description.Behaviors.Add(storeBehavior); //WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior(); //idleBehavior.TimeToUnload = TimeSpan.FromSeconds(0); //host.Description.Behaviors.Add(idleBehavior); host.Open(); IServiceStarter client = ChannelFactory <IServiceStarter> .CreateChannel( new NetNamedPipeBinding(), new EndpointAddress(baseAddr)); client.Start(); waitEvent.WaitOne(TimeSpan.FromMinutes(2)); Console.WriteLine("Program exiting..."); } catch (Exception exception) { Console.WriteLine("Unhandled exception: {0}", exception.Message); } finally { if (host != null) { host.Close(); } } }
private void InitializeWorkflowManager(Application applicationReference, String sqlPersistenceConnection) { application = applicationReference; System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService persistenceService; workflowRuntime.WorkflowCreated += new EventHandler <WorkflowEventArgs>(WorkflowCreated); workflowRuntime.WorkflowStarted += new EventHandler <WorkflowEventArgs>(WorkflowStarted); workflowRuntime.WorkflowIdled += new EventHandler <WorkflowEventArgs>(WorkflowIdled); workflowRuntime.WorkflowCompleted += new EventHandler <WorkflowCompletedEventArgs>(WorkflowCompleted); workflowRuntime.WorkflowTerminated += new EventHandler <WorkflowTerminatedEventArgs>(WorkflowTerminated); workflowRuntime.WorkflowSuspended += new EventHandler <WorkflowSuspendedEventArgs>(WorkflowSuspended); workflowRuntime.WorkflowResumed += new EventHandler <WorkflowEventArgs>(WorkflowResumed); workflowRuntime.WorkflowPersisted += new EventHandler <WorkflowEventArgs>(WorkflowPersisted); workflowRuntime.WorkflowLoaded += new EventHandler <WorkflowEventArgs>(WorkflowLoaded); workflowRuntime.WorkflowAborted += new EventHandler <WorkflowEventArgs>(WorkflowAborted); workflowRuntime.WorkflowUnloaded += new EventHandler <WorkflowEventArgs>(WorkflowUnloaded); workflowService.OnUserInteractionRequest += new EventHandler <Mercury.Server.Workflows.UserInteractions.Request.RequestEventArgs> (WorkflowService_OnUserInteractionRequest); persistenceService = new System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService(sqlPersistenceConnection); // workflowRuntime.AddService ((new System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService (sqlPersistenceConnection, false, new TimeSpan (1, 0, 0), new TimeSpan (1, 0, 0)))); workflowRuntime.AddService(persistenceService); workflowRuntime.AddService(dataExchageService); dataExchageService.AddService(workflowService); }