AspNetCompatibilityRequirementsAttribute.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 / Activation / AspNetCompatibilityRequirementsAttribute.cs / 1 / AspNetCompatibilityRequirementsAttribute.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Activation
{ 
    using System.Collections.Generic;
    using System.ServiceModel.Channels; 
    using System.ServiceModel.Description; 
    using System.Collections.ObjectModel;
    using System.ServiceModel.Dispatcher; 

    // This attribute specifies what the service implementation requires for AspNet Integration mode.
    [AttributeUsage(ServiceModelAttributeTargets.ServiceBehavior)]
    public sealed class AspNetCompatibilityRequirementsAttribute : Attribute, IServiceBehavior 
    {
        AspNetCompatibilityRequirementsMode requirementsMode = AspNetCompatibilityRequirementsMode.NotAllowed; 
 
        // NotAllowed: Validates that the service is not running in the AspNetCompatibility mode.
        // 
        // Required: Validates that service runs in the AspNetCompatibility mode only.
        //
        // Allowed: Allows both AspNetCompatibility mode and the default Indigo mode.
        // 
        public AspNetCompatibilityRequirementsMode RequirementsMode
        { 
            get { return requirementsMode; } 
            set
            { 
                AspNetCompatibilityRequirementsModeHelper.Validate(value);
                requirementsMode = value;
            }
        } 

        void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection endpoints, BindingParameterCollection parameters) 
        { 
        }
 
        void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            if (description == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); 

            // Ignore this attribute for self-hosted services. 
            if (!ServiceHostingEnvironment.IsHosted) 
            {
                if (requirementsMode == AspNetCompatibilityRequirementsMode.Required) 
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.Hosting_CompatibilityServiceNotHosted)));
                }
 
                return;
            } 
 
            if (requirementsMode == AspNetCompatibilityRequirementsMode.Allowed)
            { 
                return;
            }
            else if (ServiceHostingEnvironment.AspNetCompatibilityEnabled &&
                requirementsMode == AspNetCompatibilityRequirementsMode.NotAllowed) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.Hosting_ServiceCompatibilityNotAllowed))); 
            } 
            else if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled &&
                requirementsMode == AspNetCompatibilityRequirementsMode.Required) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.Hosting_ServiceCompatibilityRequire)));
            }
        } 

        void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) 
        { 
        }
    } 
}


// 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