internal void InitializeFrom(PeerCustomResolverSettings settings)
 {
     if (settings == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("settings");
     }
     if (settings.Address != null)
     {
         SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Address, settings.Address.Uri);
         this.Identity.InitializeFrom(settings.Address.Identity);
     }
     if (settings.Resolver != null)
     {
         SetPropertyValueIfNotDefaultValue(ConfigurationStrings.PeerResolverType, settings.Resolver.GetType().AssemblyQualifiedName);
     }
     if (settings.Binding != null)
     {
         SetPropertyValueIfNotDefaultValue(ConfigurationStrings.BindingConfiguration, PeerStrings.PeerCustomResolver + Guid.NewGuid().ToString());
         string sectionName;
         BindingsSection.TryAdd(this.BindingConfiguration,
                                settings.Binding,
                                out sectionName);
         this.Binding = sectionName;
     }
 }
        void ValidateSection()
        {
            ContextInformation context = ConfigurationHelpers.GetEvaluationContext(this);

            if (context != null)
            {
                foreach (ServiceElement service in this.Services)
                {
                    BehaviorsSection.ValidateServiceBehaviorReference(service.BehaviorConfiguration, context, service);

                    foreach (ServiceEndpointElement endpoint in service.Endpoints)
                    {
                        if (string.IsNullOrEmpty(endpoint.Kind))
                        {
                            if (!string.IsNullOrEmpty(endpoint.EndpointConfiguration))
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidAttribute, "endpointConfiguration", "endpoint", "kind")));
                            }
                            if (string.IsNullOrEmpty(endpoint.Binding))
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.RequiredAttributeMissing, "binding", "endpoint")));
                            }
                        }
                        if (string.IsNullOrEmpty(endpoint.Binding) && !string.IsNullOrEmpty(endpoint.BindingConfiguration))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidAttribute, "bindingConfiguration", "endpoint", "binding")));
                        }
                        BehaviorsSection.ValidateEndpointBehaviorReference(endpoint.BehaviorConfiguration, context, endpoint);
                        BindingsSection.ValidateBindingReference(endpoint.Binding, endpoint.BindingConfiguration, context, endpoint);
                        StandardEndpointsSection.ValidateEndpointReference(endpoint.Kind, endpoint.EndpointConfiguration, context, endpoint);
                    }
                }
            }
        }
 // Methods
 internal ConfigWriter(System.Configuration.Configuration configuration)
 {
     this.bindingsSection = BindingsSection.GetSection(configuration);
     ServiceModelSectionGroup sectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
     this.channels = sectionGroup.Client.Endpoints;
     this.config = configuration;
 }
Example #4
0
        private void ValidateSection()
        {
            ContextInformation evaluationContext = ConfigurationHelpers.GetEvaluationContext(this);

            if (evaluationContext != null)
            {
                foreach (ChannelEndpointElement element in this.Endpoints)
                {
                    if (string.IsNullOrEmpty(element.Kind))
                    {
                        if (!string.IsNullOrEmpty(element.EndpointConfiguration))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidAttribute", new object[] { "endpointConfiguration", "endpoint", "kind" })));
                        }
                        if (string.IsNullOrEmpty(element.Binding))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("RequiredAttributeMissing", new object[] { "binding", "endpoint" })));
                        }
                        if (string.IsNullOrEmpty(element.Contract))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("RequiredAttributeMissing", new object[] { "contract", "endpoint" })));
                        }
                    }
                    if (string.IsNullOrEmpty(element.Binding) && !string.IsNullOrEmpty(element.BindingConfiguration))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidAttribute", new object[] { "bindingConfiguration", "endpoint", "binding" })));
                    }
                    BehaviorsSection.ValidateEndpointBehaviorReference(element.BehaviorConfiguration, evaluationContext, element);
                    BindingsSection.ValidateBindingReference(element.Binding, element.BindingConfiguration, evaluationContext, element);
                    StandardEndpointsSection.ValidateEndpointReference(element.Kind, element.EndpointConfiguration, evaluationContext, element);
                }
            }
        }
        internal static BindingCollectionElement UnsafeGetAssociatedBindingCollectionElement(ContextInformation evaluationContext, string bindingCollectionName)
        {
            BindingCollectionElement retVal          = null;
            BindingsSection          bindingsSection = (BindingsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.BindingsSectionGroupPath);

            if (null != bindingsSection)
            {
                bindingsSection.UpdateBindingSections(evaluationContext);
                try
                {
                    retVal = bindingsSection[bindingCollectionName];
                }
                catch (KeyNotFoundException)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ConfigurationErrorsException(SR.GetString(SR.ConfigBindingExtensionNotFound,
                                                                            ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName))));
                }
                catch (NullReferenceException) // System.Configuration.ConfigurationElement
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ConfigurationErrorsException(SR.GetString(SR.ConfigBindingExtensionNotFound,
                                                                            ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName))));
                }
            }

            return(retVal);
        }
        internal static WebHttpBindingCollectionElement GetBindingCollectionElement()
        {
            string sectionPath = "system.serviceModel/bindings";

            BindingsSection bindings = (BindingsSection)AspNetEnvironment.Current.GetConfigurationSection(sectionPath);

            return((WebHttpBindingCollectionElement)bindings[WebHttpBinding.WebHttpBindingConfigurationStrings.WebHttpBindingCollectionElementName]);
        }
Example #7
0
        internal void Validate()
        {
            ContextInformation evaluationContext = ConfigurationHelpers.GetEvaluationContext(this);

            if ((evaluationContext != null) && !string.IsNullOrEmpty(this.Binding))
            {
                BindingsSection.ValidateBindingReference(this.Binding, this.BindingConfiguration, evaluationContext, this);
            }
        }
        internal ConfigWriter(Configuration configuration)
        {
            this.bindingTable = new Dictionary<Binding, BindingDictionaryValue>();

            this.bindingsSection = BindingsSection.GetSection(configuration);

            ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
            this.channels = serviceModelSectionGroup.Client.Endpoints;
            this.config = configuration;
        }
 internal void InitializeFrom(IssuedSecurityTokenParameters source, bool initializeNestedBindings)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
     }
     this.KeyType = source.KeyType;
     if (source.KeySize > 0)
     {
         this.KeySize = source.KeySize;
     }
     this.TokenType = source.TokenType;
     if (source.IssuerAddress != null)
     {
         this.Issuer.InitializeFrom(source.IssuerAddress);
     }
     if (source.DefaultMessageSecurityVersion != null)
     {
         this.DefaultMessageSecurityVersion = source.DefaultMessageSecurityVersion;
     }
     if ((source.IssuerBinding != null) && initializeNestedBindings)
     {
         string str;
         this.Issuer.BindingConfiguration = this.Issuer.Address.ToString();
         BindingsSection.TryAdd(this.Issuer.BindingConfiguration, source.IssuerBinding, out str);
         this.Issuer.Binding = str;
     }
     if (source.IssuerMetadataAddress != null)
     {
         this.IssuerMetadata.InitializeFrom(source.IssuerMetadataAddress);
     }
     foreach (XmlElement element in source.AdditionalRequestParameters)
     {
         this.AdditionalRequestParameters.Add(new XmlElementElement(element));
     }
     foreach (ClaimTypeRequirement requirement in source.ClaimTypeRequirements)
     {
         this.ClaimTypeRequirements.Add(new ClaimTypeElement(requirement.ClaimType, requirement.IsOptional));
     }
     foreach (IssuedSecurityTokenParameters.AlternativeIssuerEndpoint endpoint in source.AlternativeIssuerEndpoints)
     {
         IssuedTokenParametersElement item = new IssuedTokenParametersElement();
         item.Issuer.InitializeFrom(endpoint.IssuerAddress);
         if (initializeNestedBindings)
         {
             string str2;
             item.Issuer.BindingConfiguration = item.Issuer.Address.ToString();
             BindingsSection.TryAdd(item.Issuer.BindingConfiguration, endpoint.IssuerBinding, out str2);
             item.Issuer.Binding = str2;
         }
         this.OptionalIssuedTokenParameters.Add(item);
     }
 }
        internal static bool TryAdd(string name, Binding binding, out string bindingSectionName)
        {
            // TryAdd built on assumption that BindingsSectionGroup.Configuration is valid.
            // This should be protected at the callers site.  If assumption is invalid, then
            // configuration system is in an indeterminate state.  Need to stop in a manner that
            // user code can not capture.
            if (null == BindingsSection.Configuration)
            {
                Fx.Assert("The TryAdd(string name, Binding binding, Configuration config, out string binding) variant of this function should always be called first. The Configuration object is not set.");
                DiagnosticUtility.FailFast("The TryAdd(string name, Binding binding, Configuration config, out string binding) variant of this function should always be called first. The Configuration object is not set.");
            }

            bool            retval = false;
            string          outBindingSectionName = null;
            BindingsSection sectionGroup          = BindingsSection.GetSection(BindingsSection.Configuration);

            sectionGroup.UpdateBindingSections();
            foreach (string sectionName in sectionGroup.BindingCollectionElements.Keys)
            {
                BindingCollectionElement bindingCollectionElement = sectionGroup.BindingCollectionElements[sectionName];

                // Save the custom bindings as the last choice
                if (!(bindingCollectionElement is CustomBindingCollectionElement))
                {
                    MethodInfo tryAddMethod = bindingCollectionElement.GetType().GetMethod("TryAdd", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (tryAddMethod != null)
                    {
                        retval = (bool)tryAddMethod.Invoke(bindingCollectionElement, new object[] { name, binding, BindingsSection.Configuration });
                        if (retval)
                        {
                            outBindingSectionName = sectionName;
                            break;
                        }
                    }
                }
            }
            if (!retval)
            {
                // Much of the time, the custombinding should come out ok.
                CustomBindingCollectionElement customBindingSection = CustomBindingCollectionElement.GetBindingCollectionElement();
                retval = customBindingSection.TryAdd(name, binding, BindingsSection.Configuration);
                if (retval)
                {
                    outBindingSectionName = ConfigurationStrings.CustomBindingCollectionElementName;
                }
            }

            // This little oddity exists to make sure that the out param is assigned to before the method
            // exits.
            bindingSectionName = outBindingSectionName;
            return(retval);
        }
        internal static bool TryAdd(string name, Binding binding, Configuration config, out string bindingSectionName)
        {
            bool retval = false;

            BindingsSection.Configuration = config;
            try
            {
                retval = BindingsSection.TryAdd(name, binding, out bindingSectionName);
            }
            finally
            {
                BindingsSection.Configuration = null;
            }
            return(retval);
        }
Example #12
0
        internal void InitializeFrom(FederatedMessageSecurityOverHttp security)
        {
            if (security == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
            }
            this.NegotiateServiceCredential = security.NegotiateServiceCredential;
            this.AlgorithmSuite             = security.AlgorithmSuite;
            this.IssuedKeyType = security.IssuedKeyType;
            if (!security.EstablishSecurityContext)
            {
                this.EstablishSecurityContext = security.EstablishSecurityContext;
            }
            if (security.IssuedTokenType != null)
            {
                this.IssuedTokenType = security.IssuedTokenType;
            }
            if (security.IssuerAddress != null)
            {
                this.Issuer.InitializeFrom(security.IssuerAddress);
            }
            if (security.IssuerMetadataAddress != null)
            {
                this.IssuerMetadata.InitializeFrom(security.IssuerMetadataAddress);
            }
            string bindingSectionName = null;

            if (security.IssuerBinding != null)
            {
                if (null == this.Issuer.Address)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigNullIssuerAddress")));
                }
                this.Issuer.BindingConfiguration = this.Issuer.Address.ToString();
                BindingsSection.TryAdd(this.Issuer.BindingConfiguration, security.IssuerBinding, out bindingSectionName);
                this.Issuer.Binding = bindingSectionName;
            }
            foreach (XmlElement element in security.TokenRequestParameters)
            {
                this.TokenRequestParameters.Add(new XmlElementElement(element));
            }
            foreach (ClaimTypeRequirement requirement in security.ClaimTypeRequirements)
            {
                ClaimTypeElement element2 = new ClaimTypeElement(requirement.ClaimType, requirement.IsOptional);
                this.ClaimTypeRequirements.Add(element2);
            }
        }
Example #13
0
        internal void InitializeFrom(FederatedMessageSecurityOverHttp security)
        {
            if (security == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
            }
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.NegotiateServiceCredential, security.NegotiateServiceCredential);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.AlgorithmSuite, security.AlgorithmSuite);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.IssuedKeyType, security.IssuedKeyType);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.EstablishSecurityContext, security.EstablishSecurityContext);
            if (security.IssuedTokenType != null)
            {
                this.IssuedTokenType = security.IssuedTokenType;
            }
            if (security.IssuerAddress != null)
            {
                this.Issuer.InitializeFrom(security.IssuerAddress);
            }
            if (security.IssuerMetadataAddress != null)
            {
                this.IssuerMetadata.InitializeFrom(security.IssuerMetadataAddress);
            }
            string bindingType = null;

            if (security.IssuerBinding != null)
            {
                if (null == this.Issuer.Address)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigNullIssuerAddress)));
                }

                this.Issuer.BindingConfiguration = this.Issuer.Address.ToString();
                BindingsSection.TryAdd(this.Issuer.BindingConfiguration,
                                       security.IssuerBinding, out bindingType);
                this.Issuer.Binding = bindingType;
            }
            foreach (XmlElement element in security.TokenRequestParameters)
            {
                this.TokenRequestParameters.Add(new XmlElementElement(element));
            }
            foreach (ClaimTypeRequirement claimTypeRequirement in security.ClaimTypeRequirements)
            {
                ClaimTypeElement element = new ClaimTypeElement(claimTypeRequirement.ClaimType, claimTypeRequirement.IsOptional);
                this.ClaimTypeRequirements.Add(element);
            }
        }
Example #14
0
        internal static HttpMessageBindingCollectionElement GetBindingCollectionElement()
        {
            BindingsSection bindings = ConfigurationManager.GetSection(SectionPath) as BindingsSection;

            if (bindings != null)
            {
                foreach (BindingCollectionElement bindingCollection in bindings.BindingCollections)
                {
                    if (bindingCollection.BindingName == HttpMessageBinding.CollectionElementName)
                    {
                        return(bindingCollection as HttpMessageBindingCollectionElement);
                    }
                }
            }

            return(null);
        }
        internal static bool TryAdd(string name, Binding binding, out string bindingSectionName)
        {
            if (Configuration == null)
            {
                DiagnosticUtility.FailFast("The TryAdd(string name, Binding binding, Configuration config, out string binding) variant of this function should always be called first. The Configuration object is not set.");
            }
            bool            flag    = false;
            string          str     = null;
            BindingsSection section = GetSection(Configuration);

            section.UpdateBindingSections();
            foreach (string str2 in section.BindingCollectionElements.Keys)
            {
                BindingCollectionElement element = section.BindingCollectionElements[str2];
                if (!(element is CustomBindingCollectionElement))
                {
                    MethodInfo method = element.GetType().GetMethod("TryAdd", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (method != null)
                    {
                        flag = (bool)method.Invoke(element, new object[] { name, binding, Configuration });
                        if (flag)
                        {
                            str = str2;
                            break;
                        }
                    }
                }
            }
            if (!flag)
            {
                flag = CustomBindingCollectionElement.GetBindingCollectionElement().TryAdd(name, binding, Configuration);
                if (flag)
                {
                    str = "customBinding";
                }
            }
            bindingSectionName = str;
            return(flag);
        }
Example #16
0
        internal static BindingCollectionElement UnsafeGetAssociatedBindingCollectionElement(ContextInformation evaluationContext, string bindingCollectionName)
        {
            BindingCollectionElement element = null;
            BindingsSection          section = (BindingsSection)UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.BindingsSectionGroupPath);

            if (section != null)
            {
                section.UpdateBindingSections(evaluationContext);
                try
                {
                    element = section[bindingCollectionName];
                }
                catch (KeyNotFoundException)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigBindingExtensionNotFound", new object[] { GetBindingsSectionPath(bindingCollectionName) })));
                }
                catch (NullReferenceException)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigBindingExtensionNotFound", new object[] { GetBindingsSectionPath(bindingCollectionName) })));
                }
            }
            return(element);
        }
Example #17
0
 internal void InitializeFrom(PeerCustomResolverSettings settings)
 {
     if (settings == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("settings");
     }
     if (settings.Address != null)
     {
         this.Address = settings.Address.Uri;
         this.Identity.InitializeFrom(settings.Address.Identity);
     }
     if (settings.Resolver != null)
     {
         this.ResolverType = settings.Resolver.GetType().AssemblyQualifiedName;
     }
     if (settings.Binding != null)
     {
         string str;
         this.BindingConfiguration = "PeerCustomResolver" + Guid.NewGuid().ToString();
         BindingsSection.TryAdd(this.BindingConfiguration, settings.Binding, out str);
         this.Binding = str;
     }
 }
Example #18
0
        internal void InitializeFrom(IssuedSecurityTokenParameters source, bool initializeNestedBindings)
        {
            if (null == source)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
            }

            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.KeyType, source.KeyType);
            if (source.KeySize > 0)
            {
                SetPropertyValueIfNotDefaultValue(ConfigurationStrings.KeySize, source.KeySize);
            }
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TokenType, source.TokenType);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.UseStrTransform, source.UseStrTransform);

            if (source.IssuerAddress != null)
            {
                this.Issuer.InitializeFrom(source.IssuerAddress);
            }

            if (source.DefaultMessageSecurityVersion != null)
            {
                SetPropertyValueIfNotDefaultValue(ConfigurationStrings.DefaultMessageSecurityVersion, source.DefaultMessageSecurityVersion);
            }

            if (source.IssuerBinding != null && initializeNestedBindings)
            {
                this.Issuer.BindingConfiguration = this.Issuer.Address.ToString();
                string bindingSectionName;
                BindingsSection.TryAdd(this.Issuer.BindingConfiguration,
                                       source.IssuerBinding,
                                       out bindingSectionName);
                this.Issuer.Binding = bindingSectionName;
            }

            if (source.IssuerMetadataAddress != null)
            {
                this.IssuerMetadata.InitializeFrom(source.IssuerMetadataAddress);
            }

            foreach (XmlElement element in source.AdditionalRequestParameters)
            {
                this.AdditionalRequestParameters.Add(new XmlElementElement(element));
            }

            foreach (ClaimTypeRequirement c in source.ClaimTypeRequirements)
            {
                this.ClaimTypeRequirements.Add(new ClaimTypeElement(c.ClaimType, c.IsOptional));
            }

            foreach (IssuedSecurityTokenParameters.AlternativeIssuerEndpoint alternativeIssuer in source.AlternativeIssuerEndpoints)
            {
                IssuedTokenParametersElement element = new IssuedTokenParametersElement();
                element.Issuer.InitializeFrom(alternativeIssuer.IssuerAddress);
                if (initializeNestedBindings)
                {
                    element.Issuer.BindingConfiguration = element.Issuer.Address.ToString();
                    string bindingSectionName;
                    BindingsSection.TryAdd(element.Issuer.BindingConfiguration,
                                           alternativeIssuer.IssuerBinding,
                                           out bindingSectionName);
                    element.Issuer.Binding = bindingSectionName;
                }
                this.OptionalIssuedTokenParameters.Add(element);
            }
        }