private Binding method_0(string string_1, ServiceModelSectionGroup serviceModelSectionGroup_0)
        {
            BindingCollectionElement bindingCollectionElement = serviceModelSectionGroup_0.Bindings[string_1];
            Binding result;

            if (bindingCollectionElement.ConfiguredBindings.Count > 0)
            {
                IBindingConfigurationElement bindingConfigurationElement = bindingCollectionElement.ConfiguredBindings[0];
                Binding binding = this.method_1(bindingConfigurationElement);
                if (bindingConfigurationElement != null)
                {
                    bindingConfigurationElement.ApplyConfiguration(binding);
                }
                if (this.nullable_0.HasValue)
                {
                    binding.CloseTimeout   = this.nullable_0.Value;
                    binding.OpenTimeout    = this.nullable_0.Value;
                    binding.ReceiveTimeout = this.nullable_0.Value;
                    binding.SendTimeout    = this.nullable_0.Value;
                }
                result = binding;
            }
            else
            {
                result = null;
            }
            return(result);
        }
Esempio n. 2
0
        internal static BindingCollectionElement UnsafeGetAssociatedBindingCollectionElement(ContextInformation evaluationContext, string bindingCollectionName)
        {
            BindingCollectionElement item            = null;
            BindingsSection          bindingsSection = (BindingsSection)Microsoft.ServiceBus.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, Microsoft.ServiceBus.Configuration.ConfigurationStrings.BindingsSectionGroupPath);

            if (bindingsSection != null)
            {
                try
                {
                    item = bindingsSection[bindingCollectionName];
                }
                catch (KeyNotFoundException keyNotFoundException)
                {
                    ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                    string           configBindingExtensionNotFound = Resources.ConfigBindingExtensionNotFound;
                    object[]         bindingsSectionPath            = new object[] { Microsoft.ServiceBus.Configuration.ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName) };
                    throw exceptionUtility.ThrowHelperError(new ConfigurationErrorsException(Microsoft.ServiceBus.SR.GetString(configBindingExtensionNotFound, bindingsSectionPath)));
                }
                catch (NullReferenceException nullReferenceException)
                {
                    ExceptionUtility exceptionUtility1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                    string           str      = Resources.ConfigBindingExtensionNotFound;
                    object[]         objArray = new object[] { Microsoft.ServiceBus.Configuration.ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName) };
                    throw exceptionUtility1.ThrowHelperError(new ConfigurationErrorsException(Microsoft.ServiceBus.SR.GetString(str, objArray)));
                }
            }
            return(item);
        }
Esempio n. 3
0
        private static BindingCollectionElement GetBindingCollectionElement(string bindingCollectionName)
        {
            BindingCollectionElement element = null;
            BindingsSection          section = (BindingsSection)ConfigurationManager.GetSection("system.serviceModel/bindings");

            try
            {
                element = section.BindingCollections.Find(new Predicate <BindingCollectionElement>(delegate(BindingCollectionElement target) { return(target.BindingName == "bindingCollectionName"); }));
            }
            catch (KeyNotFoundException)
            {
                throw new ConfigurationErrorsException();
            }
            return(element);
        }
Esempio n. 4
0
        private Binding CreateBinding(string bindingName, ServiceModelSectionGroup group)
        {
            BindingCollectionElement bindingCollectionElement = group.Bindings[bindingName];

            if (bindingCollectionElement.ConfiguredBindings.Count > 0)
            {
                IBindingConfigurationElement bindingConfigurationElement = bindingCollectionElement.ConfiguredBindings[0];
                Binding binding = this.GetBinding(bindingConfigurationElement);
                if (bindingConfigurationElement != null)
                {
                    bindingConfigurationElement.ApplyConfiguration(binding);
                }
                return(binding);
            }
            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Configures the binding for the selected endpoint
        /// </summary>
        /// <param name="bindingName"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        protected virtual Binding CreateBinding(string bindingName, ServiceModelSectionGroup group)
        {
            BindingCollectionElement bindingElementCollection = group.Bindings[bindingName];

            if (bindingElementCollection.ConfiguredBindings.Count > 0)
            {
                IBindingConfigurationElement be = bindingElementCollection.ConfiguredBindings[0];
                Binding binding = GetBinding(be);
                if (be != null)
                {
                    be.ApplyConfiguration(binding);
                }
                return(binding);
            }
            return(null);
        }
Esempio n. 6
0
        public void UserConfiguration()
        {
            ServiceModelSectionGroup config = (ServiceModelSectionGroup)ConfigurationManager.OpenExeConfiguration("Test/config/userBinding").GetSectionGroup("system.serviceModel");

            BindingsSection section = config.Bindings;

            BindingCollectionElement collectionElement = section ["userBinding"];

            Assert.AreEqual(typeof(UserBindingCollectionElement), collectionElement.GetType(), "type");

            StandardBindingElementCollection <UserBindingElement> userBindings = ((UserBindingCollectionElement)collectionElement).Bindings;

            Assert.AreEqual(2, userBindings.Count, "Count");

            Assert.AreEqual("UserBinding_1", userBindings [0].Name, "Name_1");
            Assert.AreEqual("UserBinding_2", userBindings [1].Name, "Name_2");
        }
Esempio n. 7
0
        public static Binding CreateBinding(string binding, string bindingConfiguration)
        {
            BindingCollectionElement section = ConfigUtil.BindingsSection[binding];

            if (section == null)
            {
                throw new ArgumentException(String.Format("binding section for {0} was not found.", binding));
            }
            Binding b = GetDefault(section);

            foreach (IBindingConfigurationElement el in section.ConfiguredBindings)
            {
                if (el.Name == bindingConfiguration)
                {
                    el.ApplyConfiguration(b);
                }
            }
            return(b);
        }
Esempio n. 8
0
        private Binding LookupBinding(ServiceModelSectionGroup group, string bindingName, string configurationName)
        {
            BindingCollectionElement bindingElementCollection = group.Bindings[bindingName];

            if (bindingElementCollection.ConfiguredBindings.Count == 0)
            {
                return(null);
            }

            IBindingConfigurationElement bindingConfigurationElement = bindingElementCollection.ConfiguredBindings.First(item => item.Name == configurationName);

            Binding binding = GetBinding(bindingConfigurationElement);

            if (bindingConfigurationElement != null)
            {
                bindingConfigurationElement.ApplyConfiguration(binding);
            }

            return(binding);
        }
Esempio n. 9
0
        public static Binding CreateBinding(
            string bindingSectionName,
            string bindingName,
            ServiceModelSectionGroup serviceModelSection)
        {
            Binding binding = null;

            BindingCollectionElement bindingElementCollection = serviceModelSection.Bindings[bindingSectionName];

            IBindingConfigurationElement bindingElement =
                bindingElementCollection.ConfiguredBindings.First(be => StringUtil.CompareIgnoreCase(be.Name, bindingName));

            if (bindingElement != null)
            {
                binding = GetBinding(bindingElement);

                bindingElement.ApplyConfiguration(binding);
            }

            return(binding);
        }
Esempio n. 10
0
        private Binding CreateBinding(
            string bindingName,
            ServiceModelSectionGroup group)
        {
            BindingCollectionElement bindingCollectionElem = group.Bindings[bindingName];

            if (bindingCollectionElem.ConfiguredBindings.Count == 0)
            {
                return(null);
            }

            IBindingConfigurationElement bindingElem = bindingCollectionElem.ConfiguredBindings[0];
            var binding = GetBinding(bindingElem);

            if (bindingElem != null && binding != null)
            {
                bindingElem.ApplyConfiguration(binding);
            }

            return(binding);
        }
Esempio n. 11
0
        /// <summary>
        /// Configures the binding for the selected endpoint
        /// </summary>
        /// <param name="bindingName"></param>
        /// <param name="bindingSection"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        private Binding CreateBinding(string bindingName, string bindingSection, ServiceModelSectionGroup group)
        {
            BindingCollectionElement bindingElementCollection = group.Bindings[bindingName];

            if (bindingElementCollection.ConfiguredBindings.Count > 0)
            {
                IBindingConfigurationElement be =
                    bindingElementCollection.ConfiguredBindings.Single(b => b.Name.Equals(bindingSection));



                Binding binding = GetBinding(be);
                if (be != null)
                {
                    be.ApplyConfiguration(binding);
                }

                return(binding);
            }

            return(null);
        }
Esempio n. 12
0
        /// <summary>
        /// 为所选择的终结点配置绑定
        /// </summary>
        /// <param name="bindingName"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        private Binding CreateBinding(string bindingName, ServiceModelSectionGroup group)
        {
            BindingCollectionElement bindingElementCollection = group.Bindings[bindingName];

            if (bindingElementCollection.ConfiguredBindings.Count > 0)
            {
                IBindingConfigurationElement be = bindingElementCollection.ConfiguredBindings[0];

                Binding binding = GetBinding(be);
                if (be != null)
                {
                    be.ApplyConfiguration(binding);
                }
                if (_timeout != null)
                {
                    binding.CloseTimeout   = (TimeSpan)_timeout;
                    binding.OpenTimeout    = (TimeSpan)_timeout;
                    binding.ReceiveTimeout = (TimeSpan)_timeout;
                    binding.SendTimeout    = (TimeSpan)_timeout;
                }
                return(binding);
            }
            return(null);
        }
Esempio n. 13
0
        /// <summary>
        /// 生成Binding对象
        /// <code>
        /// WCFMateHelper.BindingFactory(config, e)
        /// </code>
        /// </summary>
        /// <param name="config"></param>
        /// <param name="chanelEndpoint"></param>
        /// <returns></returns>
        public static Binding BindingFactory(System.Configuration.Configuration config, ChannelEndpointElement chanelEndpoint)
        {
            BindingsSection bindings = config.GetSection("system.serviceModel/bindings") as BindingsSection;

            BindingCollectionElement bc = bindings[chanelEndpoint.Binding];

            //chanelEndpoint.
            if (chanelEndpoint.Binding != "")
            {
                switch (chanelEndpoint.Binding.ToLower())
                {
                case "nettcpbinding":
                {
                    NetTcpBinding        ntb = new NetTcpBinding();
                    NetTcpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == chanelEndpoint.BindingConfiguration) as NetTcpBindingElement;
                    if (bce != null)
                    {
                        ntb.CloseTimeout                        = bce.CloseTimeout;
                        ntb.OpenTimeout                         = bce.OpenTimeout;
                        ntb.ReceiveTimeout                      = bce.ReceiveTimeout;
                        ntb.SendTimeout                         = bce.SendTimeout;
                        ntb.MaxBufferPoolSize                   = bce.MaxBufferPoolSize;
                        ntb.HostNameComparisonMode              = bce.HostNameComparisonMode;
                        ntb.ListenBacklog                       = (bce.ListenBacklog != 0 ? bce.ListenBacklog : ntb.ListenBacklog);
                        ntb.MaxBufferSize                       = bce.MaxBufferSize;
                        ntb.MaxConnections                      = (bce.MaxConnections == 0 ? ntb.MaxConnections : bce.MaxConnections);
                        ntb.MaxReceivedMessageSize              = bce.MaxReceivedMessageSize;
                        ntb.PortSharingEnabled                  = bce.PortSharingEnabled;
                        ntb.ReaderQuotas.MaxArrayLength         = (bce.ReaderQuotas.MaxArrayLength != 0 ? bce.ReaderQuotas.MaxArrayLength : ntb.ReaderQuotas.MaxArrayLength);
                        ntb.ReaderQuotas.MaxDepth               = (bce.ReaderQuotas.MaxDepth != 0 ? bce.ReaderQuotas.MaxDepth : ntb.ReaderQuotas.MaxDepth);
                        ntb.ReaderQuotas.MaxBytesPerRead        = (bce.ReaderQuotas.MaxBytesPerRead != 0 ? bce.ReaderQuotas.MaxBytesPerRead : ntb.ReaderQuotas.MaxBytesPerRead);
                        ntb.ReaderQuotas.MaxNameTableCharCount  = (bce.ReaderQuotas.MaxNameTableCharCount != 0 ? bce.ReaderQuotas.MaxNameTableCharCount : ntb.ReaderQuotas.MaxNameTableCharCount);
                        ntb.ReaderQuotas.MaxStringContentLength = (bce.ReaderQuotas.MaxStringContentLength != 0 ? bce.ReaderQuotas.MaxStringContentLength : ntb.ReaderQuotas.MaxStringContentLength);
                        ntb.ReliableSession                     = new OptionalReliableSession()
                        {
                            Enabled = bce.ReliableSession.Enabled, InactivityTimeout = bce.ReliableSession.InactivityTimeout, Ordered = bce.ReliableSession.Ordered
                        };
                        ntb.Security = new NetTcpSecurity()
                        {
                            Mode = SecurityMode.None
                        };
                        ntb.TransactionFlow     = bce.TransactionFlow;
                        ntb.TransactionProtocol = bce.TransactionProtocol;
                        ntb.TransferMode        = bce.TransferMode;
                    }
                    return(ntb);
                }

                case "basichttpbinding":
                {
                    BasicHttpBinding        bhb = new BasicHttpBinding(BasicHttpSecurityMode.None);
                    BasicHttpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == chanelEndpoint.BindingConfiguration) as BasicHttpBindingElement;
                    if (bce != null)
                    {
                        bhb.AllowCookies                        = bce.AllowCookies;
                        bhb.BypassProxyOnLocal                  = bce.BypassProxyOnLocal;
                        bhb.CloseTimeout                        = bce.CloseTimeout;
                        bhb.HostNameComparisonMode              = bce.HostNameComparisonMode;
                        bhb.MaxBufferPoolSize                   = bce.MaxBufferPoolSize;
                        bhb.MaxBufferSize                       = bce.MaxBufferSize;
                        bhb.MaxReceivedMessageSize              = bce.MaxReceivedMessageSize;
                        bhb.MessageEncoding                     = bce.MessageEncoding;
                        bhb.OpenTimeout                         = bce.OpenTimeout;
                        bhb.ProxyAddress                        = bce.ProxyAddress;
                        bhb.ReaderQuotas.MaxArrayLength         = (bce.ReaderQuotas.MaxArrayLength != 0 ? bce.ReaderQuotas.MaxArrayLength : bhb.ReaderQuotas.MaxArrayLength);
                        bhb.ReaderQuotas.MaxDepth               = (bce.ReaderQuotas.MaxDepth != 0 ? bce.ReaderQuotas.MaxDepth : bhb.ReaderQuotas.MaxDepth);
                        bhb.ReaderQuotas.MaxBytesPerRead        = (bce.ReaderQuotas.MaxBytesPerRead != 0 ? bce.ReaderQuotas.MaxBytesPerRead : bhb.ReaderQuotas.MaxBytesPerRead);
                        bhb.ReaderQuotas.MaxNameTableCharCount  = (bce.ReaderQuotas.MaxNameTableCharCount != 0 ? bce.ReaderQuotas.MaxNameTableCharCount : bhb.ReaderQuotas.MaxNameTableCharCount);
                        bhb.ReaderQuotas.MaxStringContentLength = (bce.ReaderQuotas.MaxStringContentLength != 0 ? bce.ReaderQuotas.MaxStringContentLength : bhb.ReaderQuotas.MaxStringContentLength);
                        bhb.ReceiveTimeout                      = bce.ReceiveTimeout;
                        bhb.SendTimeout                         = bce.SendTimeout;
                        bhb.TextEncoding                        = bce.TextEncoding;
                        bhb.TransferMode                        = bce.TransferMode;
                        bhb.UseDefaultWebProxy                  = bce.UseDefaultWebProxy;
                    }
                    return(bhb);
                }

                case "wshttpbinding":
                {
                    WSHttpBinding        bhb = new WSHttpBinding(SecurityMode.None);
                    WSHttpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == chanelEndpoint.BindingConfiguration) as WSHttpBindingElement;
                    if (bce != null)
                    {
                        bhb.AllowCookies                        = bce.AllowCookies;
                        bhb.BypassProxyOnLocal                  = bce.BypassProxyOnLocal;
                        bhb.CloseTimeout                        = bce.CloseTimeout;
                        bhb.HostNameComparisonMode              = bce.HostNameComparisonMode;
                        bhb.MaxBufferPoolSize                   = bce.MaxBufferPoolSize;
                        bhb.MaxReceivedMessageSize              = bce.MaxReceivedMessageSize;
                        bhb.MessageEncoding                     = bce.MessageEncoding;
                        bhb.OpenTimeout                         = bce.OpenTimeout;
                        bhb.ProxyAddress                        = bce.ProxyAddress;
                        bhb.ReaderQuotas.MaxArrayLength         = (bce.ReaderQuotas.MaxArrayLength != 0 ? bce.ReaderQuotas.MaxArrayLength : bhb.ReaderQuotas.MaxArrayLength);
                        bhb.ReaderQuotas.MaxDepth               = (bce.ReaderQuotas.MaxDepth != 0 ? bce.ReaderQuotas.MaxDepth : bhb.ReaderQuotas.MaxDepth);
                        bhb.ReaderQuotas.MaxBytesPerRead        = (bce.ReaderQuotas.MaxBytesPerRead != 0 ? bce.ReaderQuotas.MaxBytesPerRead : bhb.ReaderQuotas.MaxBytesPerRead);
                        bhb.ReaderQuotas.MaxNameTableCharCount  = (bce.ReaderQuotas.MaxNameTableCharCount != 0 ? bce.ReaderQuotas.MaxNameTableCharCount : bhb.ReaderQuotas.MaxNameTableCharCount);
                        bhb.ReaderQuotas.MaxStringContentLength = (bce.ReaderQuotas.MaxStringContentLength != 0 ? bce.ReaderQuotas.MaxStringContentLength : bhb.ReaderQuotas.MaxStringContentLength);
                        bhb.ReceiveTimeout                      = bce.ReceiveTimeout;
                        bhb.SendTimeout                         = bce.SendTimeout;
                        bhb.TextEncoding                        = bce.TextEncoding;
                        bhb.TransactionFlow                     = bce.TransactionFlow;
                        bhb.UseDefaultWebProxy                  = bce.UseDefaultWebProxy;
                    }
                    return(bhb);
                }
                }
            }

            throw new BindingNotFoundException(Resources.BindingNotFoundException);
        }
Esempio n. 14
0
 private static Binding GetDefault(BindingCollectionElement session)
 {
     return((Binding)typeof(BindingCollectionElement).GetMethod("GetDefault", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(session, null));
 }