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(); }
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 virtual void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { string workflowDisplayName = ""; System.ServiceModel.Activities.WorkflowServiceHost workflowServiceHost = serviceHostBase as System.ServiceModel.Activities.WorkflowServiceHost; if (null != workflowServiceHost) { workflowDisplayName = ((System.ServiceModel.Activities.WorkflowServiceHost)serviceHostBase).Activity.DisplayName; } System.ServiceModel.Activities.WorkflowServiceHost host = serviceHostBase as System.ServiceModel.Activities.WorkflowServiceHost; if (this.TrackingComponentElements != null && host != null) { foreach (TrackingComponentElement trackingComponentElement in this.TrackingComponentElements) { TrackingParticipant trackingComponent = this.CreateTrackingComponent(trackingComponentElement); if (trackingComponent != null) { if (!string.IsNullOrEmpty(trackingComponentElement.ProfileName)) { trackingComponent.TrackingProfile = this.GetProfile(trackingComponentElement.ProfileName, workflowDisplayName); } host.WorkflowExtensions.Add(trackingComponent); } else { throw new Exception(string.Format("Tracking component is not a known type: {0}", trackingComponentElement.Name)); } } } }
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(); } } }