//<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();
        }
Example #2
0
        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();
            }
        }
Example #3
0
        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();
        }
        static void Main(string[] args)
        {
            using (Session session = new Session()) {
                session.ConnectionString = DevExpressConnectionString;
                session.UpdateSchema(typeof(XpoWorkflowInstance), typeof(XpoInstanceKey));
                session.CreateObjectTypeRecords(typeof(XpoWorkflowInstance), typeof(XpoInstanceKey));
            }

            // Create service host.
            WorkflowServiceHost host = new WorkflowServiceHost(new CountingWorkflow(), new Uri(hostBaseAddress));

            // Add service endpoint.
            host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), "");

            // 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();
        }
Example #5
0
        public void TestOpenHost()
        {
            // Create service host.
            WorkflowServiceHost host = new WorkflowServiceHost(new Microsoft.Samples.BuiltInConfiguration.CountingWorkflow(), new Uri(hostBaseAddress));


            // Add service endpoint.
            host.AddServiceEndpoint("ICountingWorkflow", new NetTcpBinding(), "");

            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();

            host.Close();
        }
Example #6
0
        static void Main(string[] args)
        {
            // Create service host.
            WorkflowServiceHost host = new WorkflowServiceHost(new CountingWorkflow2(), new Uri(hostBaseAddress));

            // Add service endpoint.
            host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), "");

            // 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();
        }
Example #7
0
        static void Main(string[] args)
        {
            // Xamlx file is a workflow that waits for a client to call its Start method.
            // Once called, the workflow counts from 0 to 29, incrementing the counter
            // every 2 seconds. After every counter increment the workflow persists,
            // updating the promoted properties in the [InstancePromotedProperties] view.
            object serviceImplementation = XamlServices.Load("CounterService.xamlx");

            using (WorkflowServiceHost host = new WorkflowServiceHost(serviceImplementation))
            {
                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(ServiceEndpointAddress));

                client.Start();

                Console.WriteLine("(Press [Enter] at any time to terminate host)");
                Console.ReadLine();

                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.

            //We will not use this default instance store behavior in this particular demo.

            /*
             * 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);
             */

//DevExpress Solution Begins
            //We create the database schema as well as the required records in the service XPObjectType table (http://documentation.devexpress.com/#XPO/CustomDocument2632).
            using (var session = new Session()) {
                session.ConnectionString = DevExpressConnectionString;
                session.UpdateSchema(typeof(XpoWorkflowInstance), typeof(XpoInstanceKey));
                session.CreateObjectTypeRecords(typeof(XpoWorkflowInstance));
            }
            //Create and configure the DevExpress instance store behavior.
            var dxInstanceStoreBehavior = new WorkflowInstanceStoreBehavior(
                typeof(XpoWorkflowInstance), typeof(XpoInstanceKey), new XPObjectSpaceProvider(DevExpressConnectionString, null));

            dxInstanceStoreBehavior.WorkflowInstanceStore.RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2);
            dxInstanceStoreBehavior.WorkflowInstanceStore.InstanceCompletionAction         = InstanceCompletionAction.DeleteAll;

            //Take special note that WorkflowInstanceStore is created internally as follows:
            //WorkflowInstanceStore dxWorkflowInstanceStore = new WorkflowInstanceStore(
            //    typeof(XpoWorkflowInstance), typeof(XpoInstanceKey),
            //    new XPObjectSpaceProvider(DevExpressConnectionString, null)
            //);

            //Add the DevExpress instance store behavior to the host.
            host.Description.Behaviors.Add(dxInstanceStoreBehavior);
//DevExpress Solution Ends

            // 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();
        }