Ejemplo 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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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();
                }
            }
        }
Ejemplo n.º 4
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();
         }
     }
 }
Ejemplo n.º 5
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();
            }
        }
        /// <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());

        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
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();
            }
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
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;
        }
Ejemplo n.º 13
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();
            }
        }
Ejemplo n.º 14
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();
            }
        }