示例#1
0
        static void Main(string[] args)
        {
            ServiceHost host  = null;
            ServiceHost host2 = null;

            try
            {
                // WCF services
                host = new ServiceHost(typeof(WorkflowService));
                host.Open();

                host2 = new ServiceHost(typeof(WorkflowService2));
                host2.Open();

                // remoting
                string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                RemotingConfiguration.Configure(configFile, false);

                // workflow
                WorkflowRuntime wr = WorkflowHosting.Attach("WorkflowRuntimeConfig", "LocalServicesConfig");

                // workflowruntime handlers for trace purpose
                wr.WorkflowIdled     += new EventHandler <WorkflowEventArgs>(wr_WorkflowIdled);
                wr.WorkflowPersisted += new EventHandler <WorkflowEventArgs>(wr_WorkflowPersisted);
                wr.WorkflowCompleted += new EventHandler <WorkflowCompletedEventArgs>(wr_WorkflowCompleted);
                wr.WorkflowCreated   += new EventHandler <WorkflowEventArgs>(wr_WorkflowCreated);
                wr.WorkflowStarted   += new EventHandler <WorkflowEventArgs>(wr_WorkflowStarted);
                wr.WorkflowLoaded    += new EventHandler <WorkflowEventArgs>(wr_WorkflowLoaded);
                wr.WorkflowUnloaded  += new EventHandler <WorkflowEventArgs>(wr_WorkflowUnloaded);

                // processing
                Console.Write("Hit <enter> to exit server...\n");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
            finally
            {
                // clean-up
                WorkflowHosting.Detach();

                if (host != null)
                {
                    host.Close();
                }
                if (host2 != null)
                {
                    host2.Close();
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            string response = string.Empty;

            Process.GetCurrentProcess().Exited += new EventHandler(process_Exited);

            // test option
            bool bIsStateMachineTest = false;

            try
            {
                // hosting remoting
                string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                RemotingConfiguration.Configure(configFile, false);

                // hosting workflow and trace handlers
                WorkflowRuntime wr = WorkflowHosting.Attach("WorkflowRuntimeConfig", "LocalServicesConfig");
                wr.WorkflowIdled     += new EventHandler <WorkflowEventArgs>(wr_WorkflowIdled);
                wr.WorkflowPersisted += new EventHandler <WorkflowEventArgs>(wr_WorkflowPersisted);
                wr.WorkflowCompleted += new EventHandler <WorkflowCompletedEventArgs>(wr_WorkflowCompleted);
                wr.WorkflowCreated   += new EventHandler <WorkflowEventArgs>(wr_WorkflowCreated);
                wr.WorkflowStarted   += new EventHandler <WorkflowEventArgs>(wr_WorkflowStarted);
                wr.WorkflowLoaded    += new EventHandler <WorkflowEventArgs>(wr_WorkflowLoaded);
                wr.WorkflowUnloaded  += new EventHandler <WorkflowEventArgs>(wr_WorkflowUnloaded);

                // workflow init data
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                HybridDictionary            initData   = new HybridDictionary();
                initData["abc"] = 12345;
                dictionary.Add("InitData", initData);
                dictionary.Add("Counter", 10);

                // create and persiste our test state machine (myWorkflow6), - SqlWorkflowPersistenceService is required
                Guid stateMachineId = Guid.NewGuid();
                bool bIsUnloaded    = WorkflowInvoker.CreateAndUnload("myWorkflow6", dictionary, stateMachineId);
                Console.WriteLine("StateMachine {0} has been created and unloaded={1}\n\n", stateMachineId, bIsUnloaded);

                for (int ii = 0; ii < 10000; ii++)
                {
                    // each call will have an unique context
                    using (LogicalWorkflowContext lwc = LCC.LogicalWorkflowContext)
                    {
                        // application specific Context for test purpose
                        CallContext.SetData("LogicalTicket", new LogicalTicket(Guid.NewGuid(), Convert.ToString(ii)));
                        CallContext.SetData("Ticket", Guid.NewGuid());
                        lwc.Properties["MyTest"] = DateTime.Now;

                        // some workflow init data
                        lwc.WorkflowInitData["InitData"] = initData;

                        // use this Guid (for persisted state machine) - SqlWorkflowPersistenceService is required
                        //lwc.WorkflowId = stateMachineId;

                        // endpoint scenarios for some kind of tests
                        string endpoint = "wf://localhost/myWorkflow5";   // tcp remoting (workflow5)
                        //endpoint = "tcp://localhost:1234/myWorkflow5";  // null remoting
                        //endpoint = "tcp://localhost:1234/myWorkflow6";  // tcp remoting - state machine
                        //endpoint = "wf://localhost/myWorkflow6";        // null remoting - state machine
                        //endpoint = "tcp://localhost:1234/myWorkflow4";  // tcp remoting with chaining (workflow4 -> workflow5)
                        //endpoint = "wf://localhost/myWorkflow4";        // null remoting
                        //endpoint = "wf://localhost/myWorkflow7";        // null remoting - workflow craeted by xoml
                        //endpoint = "wcf://myWorkflow4";                   // wcf/workflow invoker



                        if (bIsStateMachineTest)
                        {
                            // action 1: - standard way
                            ITest test = (ITest)Activator.GetObject(typeof(ITest), endpoint);
                            response = test.SayHello(string.Format("[{0}]: Hello world", ii));

                            // use the same state machine - SqlWorkflowPersistenceService is required
                            LCC.LogicalWorkflowContext.WorkflowId = stateMachineId;

                            // action 2: - another way how to invoke workflow
                            WorkflowInvoker.Contract <ITest>(endpoint).OneWay(string.Format("[{0}]: Hello world", ii));
                            //response = WorkflowInvoker.Contract<ITest>(endpoint).SayHello(string.Format("[{0}]: Hello world", ii));
                        }
                        else
                        {
                            // action 1:
                            ITest test = (ITest)Activator.GetObject(typeof(ITest), endpoint);
                            response = test.SayHello(string.Format("[{0}]: Hello world", ii));

                            // action 2:
                            //WorkflowInvoker.Contract<ITest>(endpoint).OneWay(string.Format("[{0}]: Hello world", ii));
                        }

                        // show CallContext
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("LWC={0}, Client.Response:    {1}, CallContext: {2}", LCC.LogicalWorkflowContext.ContextId, response, ConvertListToText(LCC.GetKeys()));
                        Console.ResetColor();

                        Console.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException == null ? ex : ex.InnerException);
                Console.ReadLine();
            }
            finally
            {
                // workflow
                WorkflowHosting.Detach();
            }
        }