예제 #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();
        }
예제 #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();
        }
예제 #3
0
        public override void Start()
        {
            if (IsRunning)
            {
                return;
            }

            using (var stream = new MemoryStream(Encoding.Default.GetBytes(Xaml)))
            {
                workflowServiceHost = new WorkflowServiceHost(XamlServices.Load(stream) as WorkflowService);
            }

            workflowServiceHost.WorkflowExtensions.Add(OutputWriter);

            workflowServiceHost.Opened += WorkflowServiceHostOnOpened;
            workflowServiceHost.Opening += WorkflowServiceHostOnOpening;
            workflowServiceHost.Closed += WorkflowServiceHostOnClosed;
            workflowServiceHost.Closing += WorkflowServiceHostOnClosing;
            workflowServiceHost.Faulted += WorkflowServiceHostOnFaulted;
            workflowServiceHost.UnknownMessageReceived += WorkflowServiceHostOnUnknownMessageReceived;

            try
            {
                OnExecutingStateChanged(new WorkflowExecutingStateEventArgs(true));
                workflowServiceHost.Open();
            }
            catch (Exception e)
            {
                OutputWriter.WriteLine(e.StackTrace);
                OnExecutingStateChanged(new WorkflowExecutingStateEventArgs(false));
            }
        }
예제 #4
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();
                }
            }
        }
예제 #5
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();
         }
     }
 }
예제 #6
0
        static void Main(string[] args)
        {
            string baseAddress = "http://localhost:8081/StopWatchService";

            try
            {

                using (WorkflowServiceHost host = new WorkflowServiceHost(new StopWatchWorkflow(), new Uri(baseAddress)))
                {
                    host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });

                    Console.WriteLine("Opening StopWatchService...");
                    host.Open();

                    Console.WriteLine("StopWatchService waiting at: " + baseAddress);
                    Console.WriteLine("Press [ENTER] to exit");
                    Console.ReadLine();
                    host.Close();
                }
            }
            catch (AddressAlreadyInUseException)
            {
                Console.WriteLine("Error - An error occurred while opening the service. Please ensure that there are no other instances of this service running.");
                Console.WriteLine("Press [ENTER] to exit");
                Console.ReadLine();
            }
            catch (CommunicationObjectFaultedException)
            {
                Console.WriteLine("Error - An error occurred while opening the service. Please ensure that there are no other instances of this service running.");
                Console.WriteLine("Press [ENTER] to exit");
                Console.ReadLine();
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting up...");
            WorkflowService service = CreateService();

            WorkflowServiceHost host = new WorkflowServiceHost(service, new Uri("http://localhost:8000/DiscoveryPrintService"));
            try
            {
                // ServiceDiscoveryBehavior and UdpDiscoveryEndpoint are being added through config
                Console.WriteLine("Opening service...");
                host.Open();

                Console.WriteLine("To terminate press ENTER");
                Console.ReadLine();

                host.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }
            
            if (host.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting service...");
                host.Abort();
            }
        }
        static void Main(string[] args)
        {
            WorkflowServiceHost host = new WorkflowServiceHost(typeof(CustomWorkflowLibrary.Workflow1),
                new Uri(@"http://localhost:8081/Demo/CustomWorkflowService"));
            host.Open();
            Console.WriteLine("停止するには、キーを入力 . . .");

            Console.ReadLine();
            host.Close();
        }
예제 #9
0
        static void Main(string[] args)
        {
            WorkflowServiceHost host = new WorkflowServiceHost(typeof(SupplierWorkflow));
            host.Description.Behaviors.Find<WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine("WorkflowTerminated: " + e.Exception.Message); };
            host.Description.Behaviors.Find<WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("WorkflowCompleted."); };
            host.Open();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Role: Supplier");
            Console.WriteLine("Press <enter> to exit");
            Console.ResetColor();
            Console.ReadLine();
            host.Close();
        }
예제 #10
0
        static void Main(string[] args)
        {
            WorkflowServiceHost workflowHost = new WorkflowServiceHost(typeof(Microsoft.WorkflowServices.Samples.ServiceWorkflow));
            

            workflowHost.Description.Behaviors.Find<WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine("WorkflowTerminated: " + e.Exception.Message); };
            workflowHost.Description.Behaviors.Find<WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("WorkflowCompleted: " + e.WorkflowInstance.InstanceId.ToString()); };
            workflowHost.Open();
            Console.WriteLine("WorkflowServiceHost is ready.");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Press <enter> to exit.");
            Console.ResetColor();
            Console.ReadLine();
            workflowHost.Close();
        }
예제 #11
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();
            }
        }
예제 #12
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();
        }
예제 #13
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();
        }
예제 #14
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();
            }
        }
예제 #15
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();
            }
        }
예제 #16
0
        WorkflowServiceHost wsh; // Host for workflow -- receives responses to requests made by this client

        #endregion Fields

        #region Constructors

        public Main()
        {
            InitializeComponent();

            statusWriter = new WindowTextWriter(statusConsole);
            WriterParticipant.Writer = statusWriter;

            addrListenForApprovalResponses = "http://localhost:" + Convert.ToString(GenerateRandomPort()) + "/ClientService";
            addrListenForApprovalRequests = "http://localhost:" + Convert.ToString(GenerateRandomPort()) + "/ApprovalService";

            // Set static variable in another class so WCF service can find the user interface instance
            ExternalToMainComm.Context = this;

            // Service Host for approving requests from other clients
            sh = new ServiceHost(typeof(Microsoft.Samples.DocumentApprovalProcess.ApprovalClient.ApprovalRequestsService), new Uri(addrListenForApprovalRequests));

            // Create the workflow and service to be hosted by the Workflow ServiceHost
            Activity element = new ClientRequestApprovalWorkflow();
            WorkflowService wshservice = new WorkflowService
            {
                Name = "ApprovalMonitor",
                ConfigurationName = "Microsoft.Samples.DocumentApprovalProcess.ApprovalClient.ApprovalMonitor",
                Body = element
            };

            wsh = new WorkflowServiceHost(wshservice, new Uri(addrListenForApprovalResponses));

            subscriptionDC = new DiscoveryClient(new UdpDiscoveryEndpoint());
            approvalDC = new DiscoveryClient(new UdpDiscoveryEndpoint());

            sh.Open();
            wsh.Open();

            statusWriter.WriteLine(addrListenForApprovalResponses);
            statusWriter.WriteLine(addrListenForApprovalRequests);
        }
예제 #17
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();
            }
        }
예제 #18
0
        static void Main(string[] args)
        {
            Console.Title = "Service";
            Console.WriteLine("Starting up");

            System.ServiceModel.Activities.WorkflowServiceHost host = new WorkflowServiceHost(GetService());
            host.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(host_UnknownMessageReceived);

            host.Open();

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();

            host.Close();
        }
예제 #19
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();
            }
        }
예제 #20
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();
            }
        }
        private WorkflowServiceHost LoadWorkflowService()
        {
            // Create Service Host.
            WorkflowServiceHost wfSvcHost = null;

            try
            {
                wfSvcHost = new WorkflowServiceHost(new ExpenseWorkflowService());
                wfSvcHost.Open();
            }
            catch (ArgumentException argEx)
            {
                EventLog.WriteEntry("ExpenseSample",
                        "\nError Loading Expense Workflow Service. " +
                        "Unable to connect to Workflow Persistence Store. " +
                        "\nPlease refer to the README.TXT for setup and installation instructions or check " +
                        "the connection string settings in the ConsoleHost configuration file." +
                        "\nException : " + argEx.Message, EventLogEntryType.Error);
                throw argEx;
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("ExpenseSample",
                    "Unable to load ExpenseWorkflowService.\n" +
                    "Exception : " + ex.Message, EventLogEntryType.Error);
                throw ex;
            }
            return wfSvcHost;
        }
        public void AttachToInitializedWorkflowServiceHostShouldThrow()
        {
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                // Arrange
                var store = testdb.CreateInstanceStore();
                var host = new WorkflowServiceHost(
                    new TestBookmark<int> { BookmarkName = "B1" }, ServiceTest.GetUniqueUri());
                host.DurableInstancingOptions.InstanceStore = store;
                host.Open();

                // Act / Assert
                AssertHelper.Throws<InvalidOperationException>(() => StateMachineStateTracker.Attach(host, store));
            }
        }
예제 #23
0
        private static WorkflowServiceHost LoadWorkflowService()
        {
            WorkflowServiceHost wfSvcHost = null;
            try
            {
                Console.Write("Loading Expense Workflow Service ... ");

                // Create WorkflowService Host.
                wfSvcHost = new WorkflowServiceHost(new ExpenseWorkflowService());
                wfSvcHost.Open();

                Console.WriteLine("Done!");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine();
                Console.WriteLine("\nError Loading Expense Workflow Service. ");
                Console.WriteLine("Unable to connect to Workflow Persistence Store. ");
                Console.WriteLine("\nPlease refer to the README.TXT for setup and installation instructions or check " +
                                  "the connection string settings in the ConsoleHost configuration file.");

                Console.WriteLine("\nException : " + argEx.Message);
                throw argEx;
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nError Loading Expense Workflow Service. ");
                Console.WriteLine("Exception : " + ex.Message);
                throw ex;
            }

            return wfSvcHost;
        }
예제 #24
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();
        }