Example #1
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ChannelManager.
                ChannelManagerService channelmgr = new ChannelManagerService();
                workflowRuntime.AddService(channelmgr);

                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("WorkflowCompleted: " + e.WorkflowInstance.InstanceId.ToString()); waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine("WorkflowTerminated: " + e.Exception.Message); waitHandle.Set(); };

                while (true)
                {
                    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Microsoft.WorkflowServices.Samples.SequentialCalculatorClient));
                    Console.WriteLine("Start SequentialCalculatorClient.");
                    instance.Start();
                    waitHandle.WaitOne();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Do another calculation? (Y)");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Press <enter> to exit.");
                    Console.ResetColor();
                    string input = Console.ReadLine();
                    if (input.Length == 0 || input[0] != 'Y')
                    {
                        break;
                    }
                    waitHandle.Reset();
                }
            }
        }
Example #2
0
        void Container0()
        {
            //ChannelManagerService.ChannelManagerService
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();
            //<snippet0>
            // Add ChannelManager.
            ChannelManagerService channelmgr = new ChannelManagerService();

            workflowRuntime.AddService(channelmgr);
            //</snippet0>
        }
Example #3
0
        void Container3()
        {
            //ChannelManagerService.ChannelManagerService(ChannelPoolSettings)
            //<snippet3>
            ChannelPoolSettings settings = new ChannelPoolSettings();

            settings.IdleTimeout  = TimeSpan.FromMinutes(10);
            settings.LeaseTimeout = TimeSpan.FromMinutes(1);
            settings.MaxOutboundChannelsPerEndpoint = 10;
            ChannelManagerService service = new ChannelManagerService(settings);
            //</snippet3>
        }
Example #4
0
        void Container2()
        {
            //ChannelManagerService.ChannelManagerService(NameValueCollection)
            //<snippet2>
            NameValueCollection parameters = new NameValueCollection();

            parameters.Add("idleTimeout", TimeSpan.FromMinutes(10).ToString());
            parameters.Add("leaseTimeout", TimeSpan.FromMinutes(1).ToString());
            parameters.Add("maxIdleChannelsPerEndpoint", "10");
            ChannelManagerService service = new ChannelManagerService(parameters);
            //</snippet2>
        }
Example #5
0
        void Container4()
        {
            //ChannelManagerService.ChannelManagerService(ChannelPoolSettings, Ilist)
            ContractDescription contractDescription = null;
            //<snippet4>
            ChannelPoolSettings settings = new ChannelPoolSettings();

            settings.IdleTimeout  = TimeSpan.FromMinutes(10);
            settings.LeaseTimeout = TimeSpan.FromMinutes(1);
            settings.MaxOutboundChannelsPerEndpoint = 10;
            IList <ServiceEndpoint> endpoints = new List <ServiceEndpoint>();

            endpoints.Add(new ServiceEndpoint(contractDescription));
            ChannelManagerService service = new ChannelManagerService(settings, endpoints);
            //</snippet4>
        }
Example #6
0
        protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            TypedOperationInfo serviceOperationInfo = this.ServiceOperationInfo;

            if (serviceOperationInfo == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_ServiceOperationInfoNotSpecified, this.Name)));
            }

            MethodInfo methodInfo = serviceOperationInfo.GetMethodInfo(executionContext);

            if (methodInfo == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR2.GetString(SR2.Error_MethodInfoNotAvailable, this.Name)));
            }

            ChannelToken channelToken = this.ChannelToken;

            LogicalChannel logicalChannel = ChannelToken.Register(this, channelToken, serviceOperationInfo.ContractType);

            if (!logicalChannel.Initialized)
            {
                logicalChannel.Initialize(channelToken.EndpointName, this.CustomAddress);
            }

            using (ChannelManagerService.ChannelTicket leasedChannel = ChannelManagerService.Take(executionContext, this.WorkflowInstanceId, logicalChannel))
            {
                using (OperationContextScope scope = new OperationContextScope((IContextChannel)leasedChannel.Channel))
                {
                    EventHandler <SendActivityEventArgs>[] invocationList = this.GetInvocationList <EventHandler <SendActivityEventArgs> >(SendActivity.BeforeSendEvent);
                    if (invocationList != null && invocationList.Length > 0)
                    {
                        base.RaiseGenericEvent(SendActivity.BeforeSendEvent, this, new SendActivityEventArgs(this));
                    }

                    SendOperationInfoHelper            helper   = this.OperationHelper;
                    WorkflowParameterBindingCollection bindings = this.ParameterBindings;

                    object[] parameters  = helper.GetInputs(this, bindings);
                    object   returnValue = null;

                    bool isSessionless  = ChannelManagerHelpers.IsSessionlessContract(logicalChannel.ContractType);
                    bool hasContext     = (logicalChannel.Context != null && logicalChannel.Context.Count > 0);
                    bool fatalException = false;

                    if (!isSessionless && hasContext)
                    {
                        ChannelManagerService.ApplyLogicalChannelContext(logicalChannel);
                    }

                    try
                    {
                        returnValue = this.InvokeOperation(methodInfo, leasedChannel.Channel, parameters);
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            fatalException = true;
                        }
                        throw;
                    }
                    finally
                    {
                        if (!fatalException &&
                            !hasContext && !isSessionless && !helper.IsOneWay)
                        {
                            ChannelManagerService.UpdateLogicalChannelContext(logicalChannel);
                        }
                    }

                    helper.PopulateOutputs(this, bindings, parameters, returnValue);

                    invocationList = this.GetInvocationList <EventHandler <SendActivityEventArgs> >(SendActivity.AfterResponseEvent);
                    if (invocationList != null && invocationList.Length > 0)
                    {
                        base.RaiseGenericEvent(SendActivity.AfterResponseEvent, this, new SendActivityEventArgs(this));
                    }
                }
            }

            return(ActivityExecutionStatus.Closed);
        }
 public ChannelManagerController(ChannelManagerService channelService)
 {
     this.channelService = channelService;
 }