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 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(); Console.WriteLine("All services ready, press any key to close the services and exit."); Console.ReadLine(); wsh.Close(); sh.Close(); }
static void Main() { System.ServiceModel.Activities.WorkflowServiceHost myServiceHost = new System.ServiceModel.Activities.WorkflowServiceHost(new Sequence1(), new Uri("http://localhost:8080/Client")); //Create an endpoint in the service host to enable comunication with the Receive activity inside the Workflow. myServiceHost.AddServiceEndpoint("IWorkflow", new BasicHttpBinding(), "IWorkflow"); //Set up SQL Instance Store string myConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=DefaultSampleStore;Integrated Security=True;Asynchronous Processing=True"; SqlWorkflowInstanceStoreBehavior sqlWorkflowInstanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(myConnectionString); myServiceHost.Description.Behaviors.Add(sqlWorkflowInstanceStoreBehavior); //Set the TimeToUnload to 0 to force the WF to be unloaded. To have a durable delay, the WF needs to be unloaded otherwise it will be thread as an in-memory delay. WorkflowIdleBehavior workflowIdleBehavior = new WorkflowIdleBehavior() { TimeToUnload = TimeSpan.FromSeconds(0) }; myServiceHost.Description.Behaviors.Add(workflowIdleBehavior); myServiceHost.Open(); Console.WriteLine("WorkflowServiceHost started"); //To create an instance of the Workflow, we are sending a message to the receive in the Workflow. IWorkflow proxy = ChannelFactory<IWorkflow>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost:8080/Client/IWorkflow")); proxy.Start(); Console.WriteLine("Client started"); Console.ReadLine(); myServiceHost.Close(); }
public static WorkflowServiceHost CreateWorkflowServiceHost() { // add the workflow implementation and application endpoint to the host WorkflowService service = new WorkflowService() { Body = PurchaseOrderWorkflow.CreateBody(), Endpoints = { // adds an application endpoint new System.ServiceModel.Endpoint { Binding = new System.ServiceModel.NetMsmqBinding("NetMsmqBindingTx"), AddressUri = new Uri("net.msmq://localhost/private/ReceiveTx"), ServiceContractName = XName.Get(PurchaseOrderWorkflow.poContractDescription.Name) } } }; WorkflowServiceHost workflowServiceHost = new WorkflowServiceHost(service); // add the workflow management behaviors IServiceBehavior idleBehavior = new WorkflowIdleBehavior { TimeToUnload = TimeSpan.Zero }; workflowServiceHost.Description.Behaviors.Add(idleBehavior); IServiceBehavior workflowUnhandledExceptionBehavior = new WorkflowUnhandledExceptionBehavior() { Action = WorkflowUnhandledExceptionAction.AbandonAndSuspend // this is also the default }; workflowServiceHost.Description.Behaviors.Add(workflowUnhandledExceptionBehavior); // add the instance store SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior() { ConnectionString = "Server=localhost\\SQLEXPRESS;Integrated Security=true;Initial Catalog=DefaultSampleStore;" }; workflowServiceHost.Description.Behaviors.Add(instanceStoreBehavior); // add a workflow management endpoint ServiceEndpoint workflowControlEndpoint = new WorkflowControlEndpoint() { Binding = new System.ServiceModel.NetNamedPipeBinding(System.ServiceModel.NetNamedPipeSecurityMode.None), Address = new System.ServiceModel.EndpointAddress("net.pipe://workflowInstanceControl") }; workflowServiceHost.AddServiceEndpoint(workflowControlEndpoint); // add the tracking participant workflowServiceHost.WorkflowExtensions.Add(new TrackingListenerConsole()); foreach (ServiceEndpoint ep in workflowServiceHost.Description.Endpoints) { Console.WriteLine(ep.Address); } return workflowServiceHost; }
/// <summary> /// Adds the standard behaviors and endpoints to our workflow service host. /// </summary> /// <param name="workflowServiceHost">The workflow service host.</param> private void AddBehaviorsAndEndpoints(WorkflowServiceHost workflowServiceHost) { // Check whether we have already initialised the service host if (workflowServiceHost.Description.Endpoints.Where(endpoint => endpoint is EnterpriseWorkflowCreationEndpoint).Any()) { return; } // Add endpoints for any services that have been defined in the workflow workflowServiceHost.AddDefaultEndpoints(); ServiceEndpoint firstEndpoint = (from endpoint in workflowServiceHost.Description.Endpoints where endpoint.IsSystemEndpoint == false select endpoint).FirstOrDefault(); BasicHttpBinding binding = new BasicHttpBinding(); EndpointAddress endpointAddress = new EndpointAddress(workflowServiceHost.BaseAddresses[0]); // Add the creation endpoint EnterpriseWorkflowCreationEndpoint creationEndpoint = new EnterpriseWorkflowCreationEndpoint(firstEndpoint != null ? firstEndpoint.Binding : binding, firstEndpoint != null ? firstEndpoint.Address : endpointAddress); workflowServiceHost.AddServiceEndpoint(creationEndpoint); // Add the SQL workflow instance store //SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore("myConnectionString"); //workflowServiceHost.DurableInstancingOptions.InstanceStore = store; // Add the idle behavior workflowServiceHost.Description.Behaviors.RemoveAll<WorkflowIdleBehavior>(); WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior { TimeToPersist = TimeSpan.FromMilliseconds(10000), TimeToUnload = TimeSpan.FromMilliseconds(10000) }; workflowServiceHost.Description.Behaviors.Add(idleBehavior); // Add the unhandled exception behavior WorkflowUnhandledExceptionBehavior unhandledExceptionBehavior = new WorkflowUnhandledExceptionBehavior { Action = WorkflowUnhandledExceptionAction.AbandonAndSuspend }; workflowServiceHost.Description.Behaviors.Add(unhandledExceptionBehavior); // Add tracking behavior EnterpriseWorkflowTrackingBehavior trackingBehavior = new EnterpriseWorkflowTrackingBehavior(); workflowServiceHost.Description.Behaviors.Add(trackingBehavior); // Add a custom extension workflowServiceHost.WorkflowExtensions.Add(() => new WorkflowHostingEnvironmentExtension()); }
private void SetupHost() { WorkflowService service = new WorkflowService { Name = "LeadResponse", Body = new WorkAssignment(), Endpoints = { new Endpoint { ServiceContractName="CreateAssignment", AddressUri = new Uri("http://localhost/CreateAssignment"), Binding = new BasicHttpBinding(), } } }; // Create a WorkflowServiceHost that listens for incoming messages _wsh = new System.ServiceModel.Activities.WorkflowServiceHost(service); SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(_connectionString); instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll; instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; _wsh.Description.Behaviors.Add(instanceStoreBehavior); WorkflowIdleBehavior wib = new WorkflowIdleBehavior(); wib.TimeToUnload = TimeSpan.FromMilliseconds(100); _wsh.Description.Behaviors.Add(wib); _wsh.Description.Behaviors.Add (new DBExtensionBehavior(_connectionString)); _wsh.Description.Behaviors.Add (new PersistAssignmentBehavior(_connectionString)); // Open the service so it will listen for messages _wsh.Open(); }