HttpBindingExtension.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 / fx / src / xsp / System / Extensions / Compilation / WCFModel / HttpBindingExtension.cs / 1305376 / HttpBindingExtension.cs

                            //------------------------------------------------------------------------------ 
// 
//   Copyright (C) Microsoft Corporation. All Rights Reserved.
// 
//----------------------------------------------------------------------------- 

using System; 
using System.Collections.Generic; 
using System.Security.Permissions;
using System.ServiceModel; 
using System.ServiceModel.Description;
using WsdlNS = System.Web.Services.Description;
using System.Xml;
using System.Xml.Schema; 
using System.Xml.Serialization;
using System.Security; 
 
#if WEB_EXTENSIONS_CODE
namespace System.Web.Compilation.WCFModel 
#else
namespace Microsoft.VSDesigner.WCFModel
#endif
{ 
    /// 
    /// Wsdl import extension to remove HttpGet and HttpPost bindings for ASMX services. 
    /// See detail in dev10 792007 
    /// 
#if WEB_EXTENSIONS_CODE 
    [PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
    [SecurityCritical]
    internal class HttpBindingExtension : IWsdlImportExtension
#else 
    [PermissionSet(SecurityAction.InheritanceDemand, Name ="FullTrust")]
    [SecurityCritical] 
    internal class HttpBindingExtension : IWsdlImportExtension 
#endif
    { 
            readonly HashSet httpBindingContracts = new HashSet();

            [SecuritySafeCritical]
            static bool ContainsHttpBindingExtension(WsdlNS.Binding wsdlBinding) 
            {
                //avoiding using wsdlBinding.Extensions.Find(typeof(WsdlNS.HttpBinding)) so the extension won't be marked as handled 
                foreach (object extension in wsdlBinding.Extensions) 
                {
                    if (extension is WsdlNS.HttpBinding) 
                    {
                        string httpVerb = ((WsdlNS.HttpBinding)extension).Verb;
                        if (httpVerb.Equals("GET", StringComparison.OrdinalIgnoreCase) || httpVerb.Equals("POST", StringComparison.OrdinalIgnoreCase))
                        { 
                            return true;
                        } 
                    } 
                }
                return false; 
            }

            [SecuritySafeCritical]
            public bool IsHttpBindingContract(ContractDescription contract) 
            {
                return contract != null && httpBindingContracts.Contains(contract); 
            } 

            [SecuritySafeCritical] 
            public void BeforeImport(WsdlNS.ServiceDescriptionCollection wsdlDocuments, XmlSchemaSet xmlSchemas, ICollection policy) {}
            [SecuritySafeCritical]
            public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context) {}
            [SecuritySafeCritical] 
            public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
            { 
                if (context != null && context.WsdlBinding != null && ContainsHttpBindingExtension(context.WsdlBinding)) 
                {
                    httpBindingContracts.Add(context.ContractConversionContext.Contract); 
                }
            }
    }
} 

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