예제 #1
0
        private WebHttpBinding CreateBindingFromConfig()
        {
            ServiceModelSectionGroup        config            = (ServiceModelSectionGroup)ConfigurationManager.OpenExeConfiguration("Test/config/webHttpBinding").GetSectionGroup("system.serviceModel");
            WebHttpBindingCollectionElement collectionElement = (WebHttpBindingCollectionElement)config.Bindings ["webHttpBinding"];

            WebHttpBindingElement el = collectionElement.Bindings ["WebHttpBinding1_Service"];

            WebHttpBinding b = new WebHttpBinding();

            el.ApplyConfiguration(b);

            return(b);
        }
예제 #2
0
        void ApplyConfiguration(string configurationName)
        {
            WebHttpBindingCollectionElement section = WebHttpBindingCollectionElement.GetBindingCollectionElement();
            WebHttpBindingElement           element = section.Bindings[configurationName];

            if (element == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
                                                                              SR2.GetString(SR2.ConfigInvalidBindingConfigurationName,
                                                                                            configurationName,
                                                                                            WebHttpBindingConfigurationStrings.WebHttpBindingCollectionElementName)));
            }
            else
            {
                element.ApplyConfiguration(this);
            }
        }
예제 #3
0
        public WebHttpBinding(string configurationName)
        {
#if !NET_2_1 && !XAMMAC_4_5
            BindingsSection       bindingsSection = ConfigUtil.BindingsSection;
            WebHttpBindingElement el = (WebHttpBindingElement)bindingsSection ["webHttpBinding"].ConfiguredBindings.FirstOrDefault(c => c.Name == configurationName);
            if (el != null)
            {
                Initialize(el.Security.Mode);                  // to initialize Transport correctly.
                el.ApplyConfiguration(this);
            }
            else if (!String.IsNullOrEmpty(configurationName))
            {
                throw new ConfigurationException(String.Format("Specified webHttpBinding configuration '{0}' was not found", configurationName));
            }
            else
            {
                Initialize(WebHttpSecurityMode.None);
            }
#else
            Initialize(WebHttpSecurityMode.None);
#endif
        }
예제 #4
0
        /// <summary>
        /// 生成Binding对象
        /// <code>
        /// WCFMateHelper.BindingFactory(serviceMeta,see)
        /// </code>
        /// </summary>
        /// <param name="wCFServiceMeta"></param>
        /// <param name="serviceEndpoint"></param>
        /// <returns></returns>
        public static Binding BindingFactory(WCFServiceMeta wCFServiceMeta, ServiceEndpointElement serviceEndpoint)
        {
            BindingsSection          bindings = wCFServiceMeta.ChildConfiguration.GetSection("system.serviceModel/bindings") as BindingsSection;
            BindingCollectionElement bc       = bindings[serviceEndpoint.Binding];

            switch (bc.BindingName.ToLower())
            {
            case "nettcpbinding":
            {
                NetTcpBinding        ntb = new NetTcpBinding();
                NetTcpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == serviceEndpoint.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 == serviceEndpoint.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 "webhttpbinding":
            {
                WebHttpBinding bhb = new WebHttpBinding(WebHttpSecurityMode.None);
                bhb.CrossDomainScriptAccessEnabled = true;
                WebHttpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == serviceEndpoint.BindingConfiguration) as WebHttpBindingElement;
                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.MessageVersion = bce.m.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.Name               = bce.Name;
                    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 == serviceEndpoint.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);
        }