示例#1
0
        static void Main(string[] args)
        {
            System.ServiceModel.Activities.WorkflowServiceHost host = null;
            try
            {
                waitEvent = new AutoResetEvent(false);
                string baseAddr = "net.pipe://localhost/GuessingGame";

                host = new System.ServiceModel.Activities.WorkflowServiceHost(
                    new GuessingGame35Interop(), new Uri(baseAddr));

                System.Workflow.Activities.ExternalDataExchangeService des =
                    new System.Workflow.Activities.ExternalDataExchangeService();
                ggService = new GuessingGameService();
                ggService.MessageReceived +=
                    new EventHandler <MessageReceivedEventArgs>(
                        Service_MessageReceived);
                des.AddService(ggService);

                WorkflowRuntimeEndpoint endpoint = new WorkflowRuntimeEndpoint();
                endpoint.AddService(des);
                host.AddServiceEndpoint(endpoint);
                host.AddDefaultEndpoints();

                ////configure persistence
                //string connectionString = ConfigurationManager.ConnectionStrings
                //    ["InstanceStore"].ConnectionString;
                //SqlWorkflowInstanceStoreBehavior storeBehavior =
                //    new SqlWorkflowInstanceStoreBehavior(connectionString);
                //host.Description.Behaviors.Add(storeBehavior);

                //WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior();
                //idleBehavior.TimeToUnload = TimeSpan.FromSeconds(0);
                //host.Description.Behaviors.Add(idleBehavior);

                host.Open();

                IServiceStarter client =
                    ChannelFactory <IServiceStarter> .CreateChannel(
                        new NetNamedPipeBinding(), new EndpointAddress(baseAddr));

                client.Start();
                waitEvent.WaitOne(TimeSpan.FromMinutes(2));

                Console.WriteLine("Program exiting...");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unhandled exception: {0}",
                                  exception.Message);
            }
            finally
            {
                if (host != null)
                {
                    host.Close();
                }
            }
        }