コード例 #1
0
        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();
        }
コード例 #2
0
ファイル: source.cs プロジェクト: zhimaqiao51/docs
        static void Main(string[] args)
        {
            const string connectionString =
                "Server=.\\SQLEXPRESS;Initial Catalog=Persistence;Integrated Security=SSPI";
            // The Throw class derives from the Activity class, needed to construct a WorkflowServiceHost.
            Throw throwError = new Throw();

            WorkflowServiceHost host = new WorkflowServiceHost(throwError,
                                                               new Uri(@"http://microsoft/services/"));

            //<snippet1>
            // Code to create a WorkFlowServiceHost is not shown here.
            // Note that SqlWorkflowInstanceStore is in the System.Activities.DurableInstancing.dll
            host.DurableInstancingOptions.InstanceStore = new SqlWorkflowInstanceStore(connectionString);
            WorkflowIdleBehavior alteredBehavior = new WorkflowIdleBehavior();

            // Alter the time to persist and unload.
            alteredBehavior.TimeToPersist = new TimeSpan(0, 4, 0);
            alteredBehavior.TimeToUnload  = new TimeSpan(0, 5, 0);
            //Remove the existing behavior and replace it with the new one.
            host.Description.Behaviors.Remove <WorkflowIdleBehavior>();
            host.Description.Behaviors.Add(alteredBehavior);
            //</snippet1>
            Console.WriteLine(alteredBehavior.TimeToUnload.Minutes.ToString());
            //wfsh.Open();
            Console.WriteLine("closed");
            Console.ReadLine();
        }
コード例 #3
0
        private static WorkflowServiceHost CreateServiceHostCustomPersistence(
            String xamlxName, IItemSupport extension)
        {
            WorkflowService     wfService = LoadService(xamlxName);
            WorkflowServiceHost host      = new WorkflowServiceHost(wfService);

            InstanceStore store = new FileSystemInstanceStore();

            host.DurableInstancingOptions.InstanceStore = store;

            WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior()
            {
                TimeToUnload = TimeSpan.FromSeconds(0)
            };

            host.Description.Behaviors.Add(idleBehavior);

            //host.Faulted += new EventHandler(host_Faulted);

            if (extension != null)
            {
                host.WorkflowExtensions.Add(extension);
            }

            _hosts.Add(host);

            return(host);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: yongzhao1/dotnet-samples
        static void Main(string[] args)
        {
            Activity element = new ApprovalRouteAndExecute();

            WorkflowService shservice = new WorkflowService
            {
                Name = "ApprovalManager",
                ConfigurationName = "Microsoft.Samples.DocumentApprovalProcess.ApprovalManager.ApprovalManager",
                Body = element
            };

            // Cleanup old table of users from previous run
            UserManager.DeleteAllUsers();

            ServiceHost sh = new ServiceHost(typeof(Microsoft.Samples.DocumentApprovalProcess.ApprovalManager.SubscriptionManager), new Uri("http://localhost:8732/Design_Time_Addresses/service/SubscriptionManager/"));

            sh.Open();

            System.ServiceModel.Activities.WorkflowServiceHost wsh = new System.ServiceModel.Activities.WorkflowServiceHost(shservice, new Uri("http://localhost:8732/Design_TimeAddress/service/ApprovalManager"));

            // Setup persistence
            wsh.Description.Behaviors.Add(new SqlWorkflowInstanceStoreBehavior(ApprovalProcessDBConnectionString));
            WorkflowIdleBehavior wib = new WorkflowIdleBehavior();

            wib.TimeToUnload = new TimeSpan(0, 0, 2);
            wsh.Description.Behaviors.Add(wib);

            wsh.Open();

            Console.WriteLine("All services ready, press any key to close the services and exit.");

            Console.ReadLine();
            wsh.Close();
            sh.Close();
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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);
        }