public void TestOpenHostWithWrongStoreThrows() { // Create service host. WorkflowServiceHost host = new WorkflowServiceHost(new Microsoft.Samples.BuiltInConfiguration.CountingWorkflow(), new Uri(hostBaseAddress)); // Add service endpoint. host.AddServiceEndpoint("ICountingWorkflow", new NetTcpBinding(), ""); SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior("Server =localhost; Initial Catalog = WFXXX; Integrated Security = SSPI") { HostLockRenewalPeriod = new TimeSpan(0, 0, 5), RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2), InstanceCompletionAction = InstanceCompletionAction.DeleteAll, InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry, InstanceEncodingOption = InstanceEncodingOption.GZip, }; host.Description.Behaviors.Add(instanceStoreBehavior); var ex = Assert.Throws <CommunicationException>(() => host.Open()); Assert.NotNull(ex.InnerException); Assert.Equal(typeof(System.Runtime.DurableInstancing.InstancePersistenceCommandException), ex.InnerException.GetType()); Assert.Equal(CommunicationState.Faulted, host.State);//so can't be disposed. }
//<Snippet1> static void Main(string[] args) { // Create service host. WorkflowServiceHost host = new WorkflowServiceHost(CountingWorkflow(), new Uri(hostBaseAddress)); // Add service endpoint. host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), ""); // Define SqlWorkflowInstanceStore and assign it to host. SqlWorkflowInstanceStoreBehavior store = new SqlWorkflowInstanceStoreBehavior(connectionString); List <XName> variantProperties = new List <XName>() { xNS.GetName("Count") }; store.Promote("CountStatus", variantProperties, null); host.Description.Behaviors.Add(store); host.WorkflowExtensions.Add <CounterStatus>(() => new CounterStatus()); host.Open(); // This sample needs to be run with Admin privileges. // Otherwise the channel listener is not allowed to open ports. // See sample documentation for details. // Create a client that sends a message to create an instance of the workflow. ICountingWorkflow client = ChannelFactory <ICountingWorkflow> .CreateChannel(new BasicHttpBinding(), new EndpointAddress(hostBaseAddress)); client.start(); Console.WriteLine("(Press [Enter] at any time to terminate host)"); Console.ReadLine(); host.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 void TestOpenHost() { // Create service host. using (WorkflowServiceHost host = new WorkflowServiceHost(new Microsoft.Samples.BuiltInConfiguration.CountingWorkflow(), new Uri(hostBaseAddress))) { // Add service endpoint. host.AddServiceEndpoint("ICountingWorkflow", new NetTcpBinding(), ""); SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(connectionString) { HostLockRenewalPeriod = new TimeSpan(0, 0, 5), RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2), InstanceCompletionAction = InstanceCompletionAction.DeleteAll, InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry, InstanceEncodingOption = InstanceEncodingOption.GZip, }; host.Description.Behaviors.Add(instanceStoreBehavior); host.Open(); Assert.Equal(CommunicationState.Opened, host.State); // Create a client that sends a message to create an instance of the workflow. ICountingWorkflow client = ChannelFactory <ICountingWorkflow> .CreateChannel(new NetTcpBinding(), new EndpointAddress(hostBaseAddress)); client.start(); Debug.WriteLine("client.start() done."); System.Threading.Thread.Sleep(10000); Debug.WriteLine("sleep finished"); host.Close(); } }
static void Main(string[] args) { // Create service host. WorkflowServiceHost host = new WorkflowServiceHost(new CountingWorkflow(), new Uri(hostBaseAddress)); // Add service endpoint. host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), ""); // Define SqlWorkflowInstanceStoreBehavior: // Set interval to renew instance lock to 5 seconds. // Set interval to check for runnable instances to 2 seconds. // Instance Store does not keep instances after it is completed. // Select exponential back-off algorithm when retrying to load a locked instance. // Instance state information is compressed using the GZip compressing algorithm. SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(connectionString); instanceStoreBehavior.HostLockRenewalPeriod = new TimeSpan(0, 0, 5); instanceStoreBehavior.RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2); instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll; instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip; host.Description.Behaviors.Add(instanceStoreBehavior); // Open service host. host.Open(); // Create a client that sends a message to create an instance of the workflow. ICountingWorkflow client = ChannelFactory <ICountingWorkflow> .CreateChannel(new BasicHttpBinding(), new EndpointAddress(hostBaseAddress)); client.start(); Console.WriteLine("(Press [Enter] at any time to terminate host)"); Console.ReadLine(); host.Close(); }
internal SqlWorkflowInstanceStorePromotionBehavior(SqlWorkflowInstanceStoreBehavior sqlWorkflowInstanceStoreBehavior) { base.ConnectionString = sqlWorkflowInstanceStoreBehavior.ConnectionString; base.HostLockRenewalPeriod = sqlWorkflowInstanceStoreBehavior.HostLockRenewalPeriod; base.InstanceCompletionAction = sqlWorkflowInstanceStoreBehavior.InstanceCompletionAction; base.InstanceEncodingOption = sqlWorkflowInstanceStoreBehavior.InstanceEncodingOption; base.InstanceLockedExceptionAction = sqlWorkflowInstanceStoreBehavior.InstanceLockedExceptionAction; base.RunnableInstancesDetectionPeriod = sqlWorkflowInstanceStoreBehavior.RunnableInstancesDetectionPeriod; }
public static WorkflowServiceHost CreateWorkflowServiceHost() { WorkflowService service = new WorkflowService() { Body = PurchaseOrderWorkflow.CreateBody(), Endpoints = { 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); IServiceBehavior idleBehavior = new WorkflowIdleBehavior { TimeToUnload = TimeSpan.Zero }; workflowServiceHost.Description.Behaviors.Add(idleBehavior); IServiceBehavior workflowUnhandledExceptionBehavior = new WorkflowUnhandledExceptionBehavior() { Action = WorkflowUnhandledExceptionAction.AbandonAndSuspend }; workflowServiceHost.Description.Behaviors.Add(workflowUnhandledExceptionBehavior); SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior() { ConnectionString = "Server=localhost\\SQLEXPRESS;Integrated Security=true;Initial Catalog=DefaultSampleStore;" }; workflowServiceHost.Description.Behaviors.Add(instanceStoreBehavior); ServiceEndpoint workflowControlEndpoint = new WorkflowControlEndpoint() { Binding = new System.ServiceModel.NetNamedPipeBinding(System.ServiceModel.NetNamedPipeSecurityMode.None), Address = new System.ServiceModel.EndpointAddress("net.pipe://workflowInstanceControl") }; workflowServiceHost.AddServiceEndpoint(workflowControlEndpoint); workflowServiceHost.WorkflowExtensions.Add(new TrackingListenerConsole()); foreach (ServiceEndpoint ep in workflowServiceHost.Description.Endpoints) { Console.WriteLine(ep.Address); } return(workflowServiceHost); }
protected internal override object CreateBehavior() { bool useDefaultConnectionStringName = false; if (string.IsNullOrEmpty(this.ConnectionString) && string.IsNullOrEmpty(this.ConnectionStringName)) { useDefaultConnectionStringName = true; } if (!string.IsNullOrEmpty(this.ConnectionString) && !string.IsNullOrEmpty(this.ConnectionStringName)) { throw FxTrace.Exception.AsError(new InstancePersistenceException(SR.CannotSpecifyBothConnectionStringAndName)); } string connectionStringToUse; if (!string.IsNullOrEmpty(this.ConnectionStringName) || useDefaultConnectionStringName) { string connectionStringNameToUse = useDefaultConnectionStringName ? defaultConnectionStringName : this.ConnectionStringName; ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[connectionStringNameToUse]; if (settings == null) { if (useDefaultConnectionStringName) { throw FxTrace.Exception.AsError(new InstancePersistenceException(SR.MustSpecifyConnectionStringOrName)); } throw FxTrace.Exception.Argument(connectionStringName, SR.ConnectionStringNameWrong(this.ConnectionStringName)); } connectionStringToUse = settings.ConnectionString; } else { connectionStringToUse = this.ConnectionString; } SqlWorkflowInstanceStoreBehavior sqlWorkflowInstanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior { ConnectionString = connectionStringToUse, HostLockRenewalPeriod = this.HostLockRenewalPeriod, InstanceEncodingOption = this.InstanceEncodingOption, InstanceCompletionAction = this.InstanceCompletionAction, InstanceLockedExceptionAction = this.InstanceLockedExceptionAction, RunnableInstancesDetectionPeriod = this.RunnableInstancesDetectionPeriod, MaxConnectionRetries = this.MaxConnectionRetries }; return(sqlWorkflowInstanceStoreBehavior); }
/// <summary> /// Overrides the <see cref="OnStart(string[])"/> method inherited from <see cref="ServiceBase"/>. /// </summary> /// <param name="args">Arguments passed on the start of the service.</param> protected override void OnStart(string[] args) { _internalServiceHost = new ServiceHost(typeof(WorkflowService)); SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior("Server=192.168.0.252,1433\\SQL2008EXPRESS;Initial Catalog=WorkflowInstanceStore;Integrated Security=SSPI") { HostLockRenewalPeriod = TimeSpan.FromSeconds(1), InstanceCompletionAction = InstanceCompletionAction.DeleteNothing, InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry, RunnableInstancesDetectionPeriod = TimeSpan.FromSeconds(1) // Minimum allowed value. }; _internalServiceHost.Description.Behaviors.Add(instanceStoreBehavior); _internalServiceHost.Open(); }
static WorkflowServiceHost CreateHost(Activity activity, System.ServiceModel.Channels.Binding binding, EndpointAddress endpointAddress) { var host = new WorkflowServiceHost(activity); { SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior("Server =localhost; Initial Catalog = WF; Integrated Security = SSPI") { HostLockRenewalPeriod = new TimeSpan(0, 0, 5), RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2), InstanceCompletionAction = InstanceCompletionAction.DeleteAll, InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry, InstanceEncodingOption = InstanceEncodingOption.GZip, MaxConnectionRetries = 3, }; host.Description.Behaviors.Add(instanceStoreBehavior); //Make sure this is cleared defined, otherwise the bookmark is not really saved in DB though a new record is created. https://msdn.microsoft.com/en-us/library/ff729670%28v=vs.110%29.aspx WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior() { TimeToPersist = TimeSpan.Zero, TimeToUnload = TimeSpan.Zero, }; host.Description.Behaviors.Add(idleBehavior); WorkflowUnhandledExceptionBehavior unhandledExceptionBehavior = new WorkflowUnhandledExceptionBehavior() { Action = WorkflowUnhandledExceptionAction.Terminate, }; host.Description.Behaviors.Add(unhandledExceptionBehavior); ResumeBookmarkEndpoint endpoint = new ResumeBookmarkEndpoint(binding, endpointAddress); host.AddServiceEndpoint(endpoint); var debugBehavior = host.Description.Behaviors.Find <ServiceDebugBehavior>(); if (debugBehavior == null) { host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { debugBehavior.IncludeExceptionDetailInFaults = true; } } return(host); }
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(); }
// start the service static void Main(string[] args) { string persistenceConnectionString = ConfigurationManager.ConnectionStrings["WorkflowPersistence"].ConnectionString; string baseAddr = "http://localhost:8080/Contoso/HiringRequestService"; using (WorkflowServiceHost host = new WorkflowServiceHost(new HiringRequestProcessServiceDefinition(), new Uri(baseAddr))) { SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(persistenceConnectionString); instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll; instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip; host.Description.Behaviors.Add(instanceStoreBehavior); host.Description.Behaviors.Add(new WorkflowIdleBehavior() { TimeToPersist = new TimeSpan(0) }); host.WorkflowExtensions.Add(new HiringRequestInfoPersistenceParticipant()); // configure the unknown message handler host.UnknownMessageReceived += new EventHandler <System.ServiceModel.UnknownMessageReceivedEventArgs>(Program.UnknownMessageReceive); // add the control endpoint WorkflowControlEndpoint publicEndpoint = new WorkflowControlEndpoint( new BasicHttpBinding(), new EndpointAddress(new Uri("http://127.0.0.1/hiringProcess"))); host.AddServiceEndpoint(publicEndpoint); host.AddDefaultEndpoints(); // start the service Console.WriteLine("Starting ..."); host.Open(); // end when the user hits enter Console.WriteLine("Service is waiting at: " + baseAddr); Console.WriteLine("Press [Enter] to exit"); Console.ReadLine(); host.Close(); } }
private static WorkflowServiceHost CreateServiceHost( String xamlxName, IItemSupport extension) { WorkflowService wfService = LoadService(xamlxName); WorkflowServiceHost host = new WorkflowServiceHost(wfService); string connectionString = ConfigurationManager.ConnectionStrings ["InstanceStore"].ConnectionString; SqlWorkflowInstanceStoreBehavior storeBehavior = new SqlWorkflowInstanceStoreBehavior(connectionString); storeBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll; storeBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.BasicRetry; storeBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip; storeBehavior.HostLockRenewalPeriod = TimeSpan.FromMinutes(1); //promption of persisted variables List <XName> variables = new List <XName>() { XName.Get("OrderId", "ActivityLibrary.ItemSupportExtension") }; storeBehavior.Promote("OrderEntry", variables, null); host.Description.Behaviors.Add(storeBehavior); //WorkflowUnhandledExceptionBehavior exceptionBehavior = // new WorkflowUnhandledExceptionBehavior //{ // Action = WorkflowUnhandledExceptionAction.Cancel //}; //host.Description.Behaviors.Add(exceptionBehavior); WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior() { TimeToUnload = TimeSpan.FromSeconds(0) }; host.Description.Behaviors.Add(idleBehavior); //add control endpoint in code //WorkflowControlEndpoint wce = new WorkflowControlEndpoint( // new System.ServiceModel.WSHttpBinding(), // new System.ServiceModel.EndpointAddress( // "http://localhost:9000/OrderEntryControl")); //host.AddServiceEndpoint(wce); //add an extension instance for each workflow instance //host.WorkflowExtensions.Add<ItemSupportParticipant>(() => //{ // ItemSupportParticipant ext = new ItemSupportParticipant(); // ext.AddItemDefinition(101, 1.23M, 10); // ext.AddItemDefinition(202, 2.34M, 20); // ext.AddItemDefinition(303, 3.45M, 30); // return ext; //}); if (extension != null) { host.WorkflowExtensions.Add(extension); } _hosts.Add(host); return(host); }