FromRequest.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Activities / System / ServiceModel / Activities / FromRequest.cs / 1305376 / FromRequest.cs

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------

namespace System.ServiceModel.Activities 
{
    using System.Activities; 
    using System.Collections.Generic; 
    using System.Collections.ObjectModel;
    using System.Runtime; 
    using System.ServiceModel.Channels;
    using System.ServiceModel.Dispatcher;
    using SR2 = System.ServiceModel.Activities.SR;
 
    class FromRequest : NativeActivity
    { 
        Collection parameters; 

        public InOutArgument Message 
        {
            get;
            set;
        } 

        public IDispatchMessageFormatter Formatter 
        { 
            get;
            set; 
        }

        public Collection Parameters
        { 
            get
            { 
                if (this.parameters == null) 
                {
                    this.parameters = new Collection(); 
                }
                return this.parameters;
            }
        } 

        public InArgument NoPersistHandle 
        { 
            get;
            set; 
        }

        internal bool CloseMessage
        { 
            get;
            set; 
        } 

        protected override void CacheMetadata(NativeActivityMetadata metadata) 
        {
            RuntimeArgument messageArgument = new RuntimeArgument(Constants.Message, Constants.MessageType, ArgumentDirection.InOut, true);
            metadata.Bind(this.Message, messageArgument);
            metadata.AddArgument(messageArgument); 

            if (this.parameters != null) 
            { 
                int count = 0;
                foreach (OutArgument parameter in this.parameters) 
                {
                    RuntimeArgument parameterArgument = new RuntimeArgument(Constants.Parameter + count++, parameter.ArgumentType, ArgumentDirection.Out);
                    metadata.Bind(parameter, parameterArgument);
                    metadata.AddArgument(parameterArgument); 
                }
            } 
 
            RuntimeArgument noPersistHandleArgument = new RuntimeArgument(Constants.NoPersistHandle, Constants.NoPersistHandleType, ArgumentDirection.In);
            metadata.Bind(this.NoPersistHandle, noPersistHandleArgument); 
            metadata.AddArgument(noPersistHandleArgument);
        }

        protected override void Execute(NativeActivityContext context) 
        {
            Message inMessage = null; 
            try 
            {
                inMessage = this.Message.Get(context); 
                object[] outObjects;
                if (this.parameters == null || this.parameters.Count == 0)
                {
                    outObjects = Constants.EmptyArray; 
                }
                else 
                { 
                    outObjects = new object[this.parameters.Count];
                } 

                this.Formatter.DeserializeRequest(inMessage, outObjects);

                if (this.parameters != null) 
                {
                    for (int i = 0; i < this.parameters.Count; i++) 
                    { 
                        OutArgument outArgument = this.parameters[i];
                        Fx.Assert(outArgument != null, "Parameter cannot be null"); 

                        object obj = outObjects[i];
                        if (obj == null)
                        { 
                            obj = ProxyOperationRuntime.GetDefaultParameterValue(outArgument.ArgumentType);
                        } 
 
                        outArgument.Set(context, obj);
                    } 
                }
            }
            finally
            { 
                if (this.CloseMessage && inMessage != null)
                { 
                    inMessage.Close(); 
                }
 
                this.Message.Set(context, null);
                NoPersistHandle handle = (this.NoPersistHandle == null) ? null : this.NoPersistHandle.Get(context);
                if (handle != null)
                { 
                    handle.Exit(context);
                } 
            } 
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK