Exemplo n.º 1
0
        static void Main()
        {
            // Same workflow as Dataflow sample
            Activity            workflow = LoadProgram("Dataflow.xaml");
            WorkflowServiceHost host     = new WorkflowServiceHost(workflow,
                                                                   new Uri("http://localhost/Dataflow.xaml"));

            WorkflowControlEndpoint controlEndpoint = new WorkflowControlEndpoint(
                new BasicHttpBinding(),
                new EndpointAddress(new Uri("http://localhost/DataflowControl.xaml")));

            CreationEndpoint creationEndpoint = new CreationEndpoint(
                new BasicHttpBinding(),
                new EndpointAddress(new Uri("http://localhost/DataflowControl.xaml/Creation")));

            host.AddServiceEndpoint(controlEndpoint);
            host.AddServiceEndpoint(creationEndpoint);

            host.Open();

            Console.WriteLine("Host open...");

            IWorkflowCreation creationClient = new ChannelFactory <IWorkflowCreation>(creationEndpoint.Binding, creationEndpoint.Address).CreateChannel();

            // Start a new instance of the workflow
            Guid instanceId = creationClient.CreateSuspended(null);
            WorkflowControlClient controlClient = new WorkflowControlClient(controlEndpoint);

            controlClient.Unsuspend(instanceId);

            Console.WriteLine("Hit any key to exit Host...");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        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.
        }
Exemplo n.º 3
0
//<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();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string baseAddr            = "http://localhost:8080/OpScope";
            XName  serviceContractName = XName.Get("IBankService", "http://bank.org");

            WorkflowService svc = new WorkflowService
            {
                Name = serviceContractName,
                Body = new BankService()
            };

            using (WorkflowServiceHost host = new WorkflowServiceHost(svc, new Uri(baseAddr)))
            {
                host.AddServiceEndpoint(serviceContractName, new BasicHttpContextBinding(), "");
                host.Description.Behaviors.Add(new ServiceMetadataBehavior()
                {
                    HttpGetEnabled = true
                });
                Console.WriteLine("Starting ...");
                host.Open();

                Console.WriteLine("Service is waiting at: " + baseAddr);
                Console.WriteLine("Press [Enter] to exit");
                Console.ReadLine();
                host.Close();
            }
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Sequence            workflow;
            WorkflowServiceHost host = null;

            try
            {
                workflow = CreateWorkflow();
                host     = new WorkflowServiceHost(workflow, new Uri("net.pipe://localhost"));
                CreationEndpoint creationEp = new CreationEndpoint(new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), new EndpointAddress("net.pipe://localhost/workflowCreationEndpoint"));
                host.AddServiceEndpoint(creationEp);
                host.Open();
                //client using NetNamedPipeBinding
                IWorkflowCreation client = new ChannelFactory <IWorkflowCreation>(creationEp.Binding, creationEp.Address).CreateChannel();
                //client using BasicHttpBinding
                IWorkflowCreation client2 = new ChannelFactory <IWorkflowCreation>(new BasicHttpBinding(), new EndpointAddress("http://localhost/workflowCreationEndpoint")).CreateChannel();
                //create instance
                Console.WriteLine("Workflow Instance created using CreationEndpoint added in code. Instance Id: {0}", client.Create(null));
                //create another instance
                Console.WriteLine("Workflow Instance created using CreationEndpoint added in config. Instance Id: {0}", client2.Create(null));
                Console.WriteLine("Press return to exit ...");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                if (host != null)
                {
                    host.Close();
                }
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            string baseAddress = "http://localhost:8080/PropertyService";

            using (WorkflowServiceHost host = new WorkflowServiceHost(GetPropertyWorkflow(), new Uri(baseAddress)))
            {
                host.UnknownMessageReceived += new EventHandler <UnknownMessageReceivedEventArgs>(OnUnknownMessage);
                host.AddServiceEndpoint(XName.Get("IProperty", ns), new BasicHttpBinding(), baseAddress);

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                host.Description.Behaviors.Add(smb);

                try
                {
                    host.Open();

                    Console.WriteLine("Service host is open for business. Press [Enter] to close the host...");
                    Console.ReadLine();
                }
                finally
                {
                    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();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var host = new WorkflowServiceHost(
                new Leaveflow.LeaveWorkflow(),
                new Uri("http://localhost:8080/LWS"));
            host.AddDefaultEndpoints();

            host.Description.Behaviors.Add(
                new ServiceMetadataBehavior() { HttpGetEnabled = true });

            host.Description.Behaviors.Add(
                new WorkflowIdleBehavior() {
                    TimeToPersist = new TimeSpan(0, 0, 0),
                    TimeToUnload = new TimeSpan(0, 0, 0)
                });

            host.AddServiceEndpoint(
                "IMetadataExchange",
                MetadataExchangeBindings.CreateMexHttpBinding(),
                "mex");

            var store = new SqlWorkflowInstanceStore(
                "server=(local)\\sqlexpress;database=wftest;uid=sa;pwd=123456;");

            host.DurableInstancingOptions.InstanceStore = store;
            host.UnknownMessageReceived += (o, e) => {
                Console.WriteLine("\n" + e.Message + "\n");
            };
            host.Open();
            Console.WriteLine("> Server is ready.");
            Console.Read();
        }
Exemplo n.º 10
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();
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Sequence            workflow;
            WorkflowServiceHost host = null;

            try
            {
                workflow = CreateWorkflow();
                host     = new WorkflowServiceHost(workflow, new Uri("net.pipe://localhost"));
                ResumeBookmarkEndpoint endpoint = new ResumeBookmarkEndpoint(new NetNamedPipeBinding(NetNamedPipeSecurityMode.None), new EndpointAddress("net.pipe://localhost/workflowCreationEndpoint"));
                host.AddServiceEndpoint(endpoint);
                host.Open();
                IWorkflowCreation client = new ChannelFactory <IWorkflowCreation>(endpoint.Binding, endpoint.Address).CreateChannel();
                //create an instance
                Guid id = client.Create(null);
                Console.WriteLine("Workflow instance {0} created", id);
                //resume bookmark
                client.ResumeBookmark(id, "hello", "Hello World!");
                Console.WriteLine("Press return to exit ...");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                if (host != null)
                {
                    host.Close();
                }
            }
        }
        static void Main()
        {
            // Same workflow as Dataflow sample
            Activity            workflow = LoadProgram("Dataflow.xaml");
            WorkflowServiceHost host     = new WorkflowServiceHost(workflow,
                                                                   new Uri("http://localhost/Dataflow.xaml"));

            host.Description.Behaviors.Add(new SqlWorkflowInstanceStoreBehavior
            {
                ConnectionString                 = ConfigurationManager.ConnectionStrings["persistenceStore"].ConnectionString,
                InstanceEncodingOption           = InstanceEncodingOption.None,
                InstanceCompletionAction         = InstanceCompletionAction.DeleteAll,
                InstanceLockedExceptionAction    = InstanceLockedExceptionAction.NoRetry,
                HostLockRenewalPeriod            = new TimeSpan(0, 0, 30),
                RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 5)
            });

            WorkflowControlEndpoint controlEndpoint = new WorkflowControlEndpoint(
                new BasicHttpBinding(),
                new EndpointAddress(new Uri("http://localhost/DataflowControl.xaml")));

            CreationEndpoint creationEndpoint = new CreationEndpoint(
                new BasicHttpBinding(),
                new EndpointAddress(new Uri("http://localhost/DataflowControl.xaml/Creation")));


            host.AddServiceEndpoint(controlEndpoint);
            host.AddServiceEndpoint(creationEndpoint);

            host.Open();

            Console.WriteLine("Host open...");

            IWorkflowCreation creationClient = new ChannelFactory <IWorkflowCreation>(creationEndpoint.Binding, creationEndpoint.Address).CreateChannel();

            // Start a new instance of the workflow
            Guid instanceId = creationClient.CreateSuspended(null);
            WorkflowControlClient controlClient = new WorkflowControlClient(controlEndpoint);

            controlClient.Unsuspend(instanceId);

            Console.WriteLine("Hit any key to exit Host...");
            Console.ReadLine();
        }
Exemplo n.º 13
0
        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;
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        public void TestOpenHostWithoutContractImpThrows()
        {
            // Create service host.
            using (WorkflowServiceHost host = new WorkflowServiceHost(new Plus(), new Uri(hostBaseAddress)))
            {
                Assert.Throws <InvalidOperationException>(()
                                                          => host.AddServiceEndpoint("ICountingWorkflow", new NetTcpBinding(), ""));

                Assert.Equal(CommunicationState.Created, host.State);
            }
        }
Exemplo n.º 16
0
        //Define WorkflowServiceHost
        static WorkflowServiceHost ServiceHostFactory(AutoResetEvent syncEvent)
        {
            WorkflowServiceHost host = new WorkflowServiceHost(ServerWorkflow());

            host.AddServiceEndpoint(Constants.ServiceContractName, Constants.ServerEndpoint.Binding, Constants.ServerAddress);

            host.Description.Behaviors.Find <ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;

            host.WorkflowExtensions.Add(new EventTrackingParticipant(syncEvent));

            return(host);
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            using (WorkflowServiceHost host = new WorkflowServiceHost(GetServiceWorkflow(), new Uri(Constants.ServiceAddress)))
            {
                host.AddServiceEndpoint(Constants.POContractName, Constants.Binding, Constants.ServiceAddress);

                host.Open();
                Console.WriteLine("Service waiting at: " + Constants.ServiceAddress);
                Console.WriteLine("Press [ENTER] to exit");
                Console.ReadLine();
                host.Close();
            }
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            string addr = "http://localhost:8080/Service";

            using (WorkflowServiceHost host = new WorkflowServiceHost(GetServiceWorkflow()))
            {
                host.AddServiceEndpoint(contract, new BasicHttpBinding(), addr);

                host.Open();
                Console.WriteLine("Service waiting at: " + addr);
                Console.WriteLine("Press [ENTER] to exit");
                Console.ReadLine();
                host.Close();
            }
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            Console.WriteLine("Setting up queue");

            try
            {
                // Setup the queue
                CreateMessageQueue();
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("MSMQ is not installed or is not configured properly to run the sample. See readme for more info.");

                return;
            }

            Console.WriteLine("\nStarting client to queue messages");

            // Run the client to enqueue some messages for the service to process later
            WorkflowInvoker.Invoke(Client.Create());

            Console.WriteLine("Client finished");

            // Create the service and host it to start processing messages
            WorkflowService service = new WorkflowService
            {
                Name = "RewardsPointsWorkflowService",
                Body = Service.Create()
            };

            using (WorkflowServiceHost host = new WorkflowServiceHost(service))
            {
                // Specify the Contract, Binding and Address to service
                host.AddServiceEndpoint(Shared.Contract, Shared.Binding, Shared.Address);

                Console.WriteLine("\nStarting service to process messages");

                // Start service and begin processing messages
                host.Open();

                Console.WriteLine("Hit enter to quit...");

                Console.ReadLine();
            }

            // Cleanup queue
            DeleteMessageQueue();
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            using (WorkflowServiceHost host = new WorkflowServiceHost(GetServiceWorkflow(), new Uri(Constants.ServiceAddress)))
            {
                host.Description.Behaviors.Add(new ServiceMetadataBehavior()
                {
                    HttpGetEnabled = true
                });
                host.Description.Behaviors.Find <ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
                host.AddServiceEndpoint(Constants.POContractName, Constants.Binding, Constants.ServiceAddress);

                host.Open();
                Console.WriteLine("FaultService waiting at: " + Constants.ServiceAddress);
                Console.WriteLine("Press [ENTER] to exit");
                Console.ReadLine();
                host.Close();
            }
        }
Exemplo n.º 22
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();
        }
Exemplo n.º 23
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();
        }
Exemplo n.º 24
0
        // 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();
            }
        }
Exemplo n.º 25
0
        public void TestMultiplyXY()
        {
            // Create service host.
            using (WorkflowServiceHost host = new WorkflowServiceHost(new Fonlow.Activities.MultiplyWorkflow2(), new Uri(hostBaseAddress)))
            {
                Debug.WriteLine("host created.");
                // Add service endpoint.
                host.AddServiceEndpoint("ICalculation", new NetTcpBinding(), "");

                host.Open();
                Debug.WriteLine("host opened");
                Assert.Equal(CommunicationState.Opened, host.State);


                // Create a client that sends a message to create an instance of the workflow.
                var client = ChannelFactory <ICalculation> .CreateChannel(new NetTcpBinding(), new EndpointAddress(hostBaseAddress));

                var r = client.MultiplyXY(3, 7);

                Assert.Equal(21, r);
            }
        }
        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();
        }