Esempio n. 1
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));
            }
        }
Esempio n. 2
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();
        }
Esempio 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();
                }
            }
        }
Esempio 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();
         }
     }
 }
Esempio 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();
        }
Esempio n. 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();
            }
        }
Esempio n. 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();
        }
 internal DurableInstanceManager(WorkflowServiceHost host)
 {
     this.DurableInstancingOptions = new System.ServiceModel.Activities.DurableInstancingOptions(this);
     this.createOwnerCommand = new CreateWorkflowOwnerCommand();
     this.instanceMetadataChanges = new Dictionary<XName, InstanceValue>();
     this.thisLock = new object();
     InstanceValue value2 = new InstanceValue(XNamespace.Get("http://tempuri.org").GetName("Sentinel"));
     this.createOwnerCommand.InstanceOwnerMetadata.Add(WorkflowNamespace.WorkflowHostType, value2);
     this.instanceMetadataChanges.Add(WorkflowNamespace.WorkflowHostType, value2);
     this.instanceMetadataChanges.Add(PersistenceMetadataNamespace.InstanceType, new InstanceValue(WorkflowNamespace.WorkflowHostType, InstanceValueOptions.WriteOnly));
     this.Host = host;
 }
 private PersistenceProviderDirectory(Activity workflowDefinition, WorkflowServiceHost serviceHost, DurableConsistencyScope consistencyScope, int maxInstances)
 {
     Fx.AssertAndThrow(maxInstances > 0, "MaxInstance must be greater than zero on PPD.");
     this.workflowDefinition = workflowDefinition;
     this.serviceHost = serviceHost;
     this.ConsistencyScope = consistencyScope;
     this.MaxInstances = maxInstances;
     this.throttle = new InstanceThrottle(this.MaxInstances);
     this.pipelinesInUse = new HashSet<PersistencePipeline>();
     this.keyMap = new Dictionary<Guid, PersistenceContext>();
     this.instanceCache = new Dictionary<Guid, PersistenceContext>();
 }
Esempio n. 11
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();
        }
        protected override void OnStart(string[] args)
        {
            try
            {
                _svcHost = LoadExpenseService();
                _wfSvcHost = LoadWorkflowService();

            }
            catch
            {
                EventLog.WriteEntry("ExpenseSample",
                    "\nFailed to start ExpenseSample Windows Service Host.", EventLogEntryType.Error);
                throw;
            }
        }
Esempio n. 13
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();
        }
Esempio n. 14
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());

        }
Esempio n. 16
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();
        }
Esempio n. 17
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();
        }
        public ControlOperationInvoker(OperationDescription description, ServiceEndpoint endpoint, CorrelationKeyCalculator correlationKeyCalculator, IOperationInvoker innerInvoker, ServiceHostBase host)
        {
            this.host = (WorkflowServiceHost) host;
            this.instanceManager = this.host.DurableInstanceManager;
            this.operationName = description.Name;
            this.isOneWay = description.IsOneWay;
            this.endpoint = endpoint;
            this.innerInvoker = innerInvoker;
            this.keyCalculator = correlationKeyCalculator;
            this.persistTimeout = this.host.PersistTimeout;
            if (description.DeclaringContract == WorkflowControlEndpoint.WorkflowControlServiceContract)
            {
                this.isControlOperation = true;
                switch (this.operationName)
                {
                    case "Cancel":
                    case "TransactedCancel":
                    case "Run":
                    case "TransactedRun":
                    case "Unsuspend":
                    case "TransactedUnsuspend":
                        this.inputParameterCount = 1;
                        return;

                    case "Abandon":
                    case "Suspend":
                    case "TransactedSuspend":
                    case "Terminate":
                    case "TransactedTerminate":
                        this.inputParameterCount = 2;
                        return;
                }
                throw Fx.AssertAndThrow("Unreachable code");
            }
            if (endpoint is WorkflowHostingEndpoint)
            {
                this.CanCreateInstance = true;
            }
            else
            {
                this.bufferedReceiveManager = this.host.Extensions.Find<System.ServiceModel.Activities.Dispatcher.BufferedReceiveManager>();
            }
        }
 private WorkflowServiceInstance(Activity workflowDefinition, Guid instanceId, WorkflowServiceHost serviceHost, PersistenceContext persistenceContext) : base(workflowDefinition)
 {
     this.serviceHost = serviceHost;
     this.instanceId = instanceId;
     this.persistTimeout = serviceHost.PersistTimeout;
     this.trackTimeout = serviceHost.TrackTimeout;
     this.bufferedReceiveManager = serviceHost.Extensions.Find<System.ServiceModel.Activities.Dispatcher.BufferedReceiveManager>();
     if (persistenceContext != null)
     {
         this.persistenceContext = persistenceContext;
         this.persistenceContext.Closed += new EventHandler(this.OnPersistenceContextClosed);
     }
     this.thisLock = new object();
     this.pendingRequests = new List<WorkflowOperationContext>();
     this.executorLock = new WorkflowExecutionLock(this);
     this.activeOperationsLock = new object();
     this.acquireReferenceSemaphore = new ThreadNeutralSemaphore(1);
     this.acquireLockTimeout = TimeSpan.MaxValue;
     this.referenceCount = 1;
     this.TryAddReference();
 }
Esempio n. 20
0
        protected override void StartInternal()
        {
            WorkflowService workflowService;

            using (var stream = new MemoryStream(Encoding.Default.GetBytes(WorkflowDesigner.Text)))
            {
                workflowService = XamlServices.Load(stream) as WorkflowService;
            }

            workflowServiceHost = new WorkflowServiceHost(workflowService);

            workflowServiceHost.WorkflowExtensions.Add(OutputWriter);
            workflowServiceHost.WorkflowExtensions.Add(InitialiseVisualTrackingParticipant(workflowService.GetWorkflowRoot()));

            workflowServiceHost.Opened += WorkflowServiceHostOnOpened;
            workflowServiceHost.Opening += WorkflowServiceHostOnOpening;
            workflowServiceHost.Closed += WorkflowServiceHostOnClosed;
            workflowServiceHost.Closing += WorkflowServiceHostOnClosing;
            workflowServiceHost.Faulted += WorkflowServiceHostOnFaulted;
            workflowServiceHost.UnknownMessageReceived += WorkflowServiceHostOnUnknownMessageReceived;
        }
Esempio n. 21
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();
            }
        }
Esempio n. 22
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();
            }
        }
Esempio n. 23
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);
        }
Esempio n. 24
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();
            }
        }
 internal WorkflowServiceHostPerformanceCounters(WorkflowServiceHost serviceHost)
 {
     this.serviceHost = serviceHost;
 }
Esempio n. 26
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;
        }
Esempio n. 28
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;
        }
Esempio n. 29
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;
        }
Esempio n. 30
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();
        }