OperationDescription.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Description / OperationDescription.cs / 1 / OperationDescription.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Description
{ 
    using System.Collections.Generic;
    using System.ServiceModel.Channels; 
    using System.Xml; 
    using System.Runtime.Serialization;
    using System.Reflection; 
    using System.Collections.ObjectModel;
    using System.CodeDom;
    using System.Diagnostics;
    using System.Net.Security; 
    using System.ServiceModel.Security;
 
    [DebuggerDisplay("Name={name}, IsInitiating={isInitiating}, IsTerminating={isTerminating}")] 
    public class OperationDescription
    { 
        XmlName name;
        bool isInitiating;
        bool isTerminating;
        ContractDescription declaringContract; 
        FaultDescriptionCollection faults;
        MessageDescriptionCollection messages; 
        KeyedByTypeCollection behaviors; 
        Collection knownTypes;
        MethodInfo beginMethod; 
        MethodInfo endMethod;
        MethodInfo syncMethod;
        ProtectionLevel protectionLevel;
        bool hasProtectionLevel; 
        bool validateRpcWrapperName = true;
        bool hasNoDisposableParameters; 
 
        public OperationDescription(string name, ContractDescription declaringContract)
        { 
            if (name == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name");
            } 
            if (name.Length == 0)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( 
                    new ArgumentOutOfRangeException("name", SR.GetString(SR.SFxOperationDescriptionNameCannotBeEmpty)));
            } 
            this.name = new XmlName(name, true /*isEncoded*/);

            if (declaringContract == null)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("declaringContract");
            } 
            this.declaringContract = declaringContract; 
            this.isInitiating = true;
            this.isTerminating = false; 
            this.faults = new FaultDescriptionCollection();
            this.messages = new MessageDescriptionCollection();
            this.behaviors = new KeyedByTypeCollection();
            this.knownTypes = new Collection(); 
        }
 
        internal OperationDescription(string name, ContractDescription declaringContract, bool validateRpcWrapperName): this(name, declaringContract) 
        {
            this.validateRpcWrapperName = validateRpcWrapperName; 
        }

        public KeyedByTypeCollection Behaviors
        { 
            get { return behaviors; }
        } 
 
        // Not serializable on purpose, metadata import/export cannot
        // produce it, only available when binding to runtime 
        public MethodInfo SyncMethod
        {
            get { return this.syncMethod; }
            set { this.syncMethod = value; } 
        }
 
        // Not serializable on purpose, metadata import/export cannot 
        // produce it, only available when binding to runtime
        public MethodInfo BeginMethod 
        {
            get { return this.beginMethod; }
            set { this.beginMethod = value; }
        } 

        internal MethodInfo OperationMethod 
        { 
            get { return SyncMethod ?? BeginMethod; }
        } 

        public ProtectionLevel ProtectionLevel
        {
            get { return this.protectionLevel; } 
            set
            { 
                if (!ProtectionLevelHelper.IsDefined(value)) 
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
                this.protectionLevel = value; 
                this.hasProtectionLevel = true;
            }
        }
 
        public bool HasProtectionLevel
        { 
            get { return this.hasProtectionLevel; } 
        }
 
        internal bool HasNoDisposableParameters
        {
            get { return this.hasNoDisposableParameters; }
            set { this.hasNoDisposableParameters = value; } 
        }
 
        // Not serializable on purpose, metadata import/export cannot 
        // produce it, only available when binding to runtime
        public MethodInfo EndMethod 
        {
            get { return this.endMethod; }
            set { this.endMethod = value; }
        } 

        public ContractDescription DeclaringContract 
        { 
            get { return this.declaringContract; }
            set 
            {
                if (value == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("DeclaringContract"); 
                }
                else 
                { 
                    this.declaringContract = value;
                } 
            }
        }

        public FaultDescriptionCollection Faults 
        {
            get { return faults; } 
        } 

        public bool IsOneWay 
        {
            get { return this.Messages.Count==1; }
        }
 
        public bool IsInitiating
        { 
            get { return this.isInitiating; } 
            set { this.isInitiating = value; }
        } 

        internal bool IsServerInitiated()
        {
            EnsureInvariants(); 
            return Messages[0].Direction == MessageDirection.Output;
        } 
 
        public bool IsTerminating
        { 
            get { return this.isTerminating; }
            set { this.isTerminating = value; }
        }
 
        public Collection KnownTypes
        { 
            get { return this.knownTypes; } 
        }
 
        // Messages[0] is the 'request' (first of MEP), and for non-oneway MEPs, Messages[1] is the 'response' (second of MEP)
        public MessageDescriptionCollection Messages
        {
            get { return messages; } 
        }
 
        internal XmlName XmlName 
        {
            get { return name; } 
        }

        internal string CodeName
        { 
            get { return name.DecodedName; }
        } 
 
        public string Name
        { 
            get { return name.EncodedName; }
        }

        internal bool IsValidateRpcWrapperName { get { return validateRpcWrapperName; } } 

        internal void EnsureInvariants() 
        { 
            if (this.Messages.Count != 1 && this.Messages.Count != 2)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new System.InvalidOperationException(SR.GetString(SR.SFxOperationMustHaveOneOrTwoMessages, this.Name)));
            }
        }
 
        internal void ResetProtectionLevel()
        { 
            this.protectionLevel = ProtectionLevel.None; 
            this.hasProtectionLevel = false;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

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