private void ApplyConfiguration(string configurationName)
        {
            NetTcpBindingElement element2 = NetTcpBindingCollectionElement.GetBindingCollectionElement().Bindings[configurationName];

            if (element2 == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidBindingConfigurationName", new object[] { configurationName, "netTcpBinding" })));
            }
            element2.ApplyConfiguration(this);
        }
        public void NetTcpBinding()
        {
            ServiceModelSectionGroup config = (ServiceModelSectionGroup)ConfigurationManager.OpenExeConfiguration("Test/config/netTcpBinding").GetSectionGroup("system.serviceModel");

            NetTcpBindingCollectionElement netTcpBinding = config.Bindings.NetTcpBinding;

            Assert.AreEqual(1, netTcpBinding.Bindings.Count, "count");

            NetTcpBindingElement binding = netTcpBinding.Bindings [0];

            Assert.AreEqual("NetTcpBinding_IHelloWorldService", binding.Name, "Name");
            Assert.AreEqual(TransactionProtocol.OleTransactions, binding.TransactionProtocol, "TransactionProtocol");
            Assert.AreEqual(SecurityMode.Transport, binding.Security.Mode, "Security.Mode");
            Assert.AreEqual(MessageCredentialType.Windows, binding.Security.Message.ClientCredentialType, "Security.Message.ClientCredentialType");
            Assert.AreEqual(ProtectionLevel.EncryptAndSign, binding.Security.Transport.ProtectionLevel, "Security.Transport.ProtectionLevel");
            Assert.AreEqual(TcpClientCredentialType.Windows, binding.Security.Transport.ClientCredentialType, "Security.Transport.ProtectionLevel");
        }
示例#3
0
        void ApplyConfiguration(string configurationName)
        {
            NetTcpBindingCollectionElement section = NetTcpBindingCollectionElement.GetBindingCollectionElement();
            NetTcpBindingElement           element = section.Bindings[configurationName];

            if (element == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
                                                                              SR.GetString(SR.ConfigInvalidBindingConfigurationName,
                                                                                           configurationName,
                                                                                           ConfigurationStrings.NetTcpBindingCollectionElementName)));
            }
            else
            {
                element.ApplyConfiguration(this);
            }
        }
示例#4
0
        internal static Binding CreateBinding(string type, string xml)
        {
            Binding binding = null;
            StandardBindingElement element = null;

            switch (type)
            {
            case "NetTcpBinding":
                binding = new NetTcpBinding();
                element = new NetTcpBindingElement();
                break;

            case "BasicHttpBinding":
                binding = new BasicHttpBinding();
                element = new BasicHttpBindingElement();
                break;

            case "WSHttpBinding":
                binding = new WSHttpBinding();
                element = new WSHttpBindingElement();
                break;

            case "NetNamedPipeBinding":
                binding = new NetNamedPipeBinding();
                element = new NetNamedPipeBindingElement();
                break;

            case "NetMsmqBinding":
                binding = new NetMsmqBinding();
                element = new NetMsmqBindingElement();
                break;

            default:
                binding = new NetTcpBinding();
                element = new NetTcpBindingElement();
                break;
            }

            Deserialize(xml, element);
            element.ApplyConfiguration(binding);

            return(binding);
        }
示例#5
0
        public void BindingSection_WithNetTcpBindingTest()
        {
            string   expectedName = "netTcpBindingConfig";
            long     expectedMaxReceivedMessageSize = 1073741824;
            long     expectedMaxBufferSize          = 1073741824;
            int      expectedMaxDepth       = 2147483647;
            TimeSpan expectedReceiveTimeout = TimeSpan.FromMinutes(10);

            string xml = $@"
<configuration>
    <configSections>
        <sectionGroup name=""system.serviceModel"" type=""CoreWCF.Configuration.ServiceModelSectionGroup, CoreWCF.ConfigurationManager"">
            <section name=""bindings"" type=""CoreWCF.Configuration.BindingsSection, CoreWCF.ConfigurationManager"" />
        </sectionGroup>         
    </configSections>  
    <system.serviceModel>         
        <bindings>            
            <netTcpBinding>
                <binding name=""{expectedName}""
                         maxReceivedMessageSize=""{expectedMaxReceivedMessageSize}""
                         maxBufferSize=""{expectedMaxBufferSize}""
                         receiveTimeout=""{expectedReceiveTimeout}"">
                    <readerQuotas maxDepth=""{expectedMaxDepth}"" />
                </binding>
            </netTcpBinding>   
        </bindings>                             
    </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                ServiceModelSectionGroup section = GetSectionFromXml(fs);

                NetTcpBindingElement actualBinding = section.Bindings.NetTcpBinding.Bindings.Cast <NetTcpBindingElement>().First();

                Assert.Equal(expectedName, actualBinding.Name);
                Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize);
                Assert.Equal(expectedMaxBufferSize, actualBinding.MaxBufferSize);
                Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout);
                Assert.Equal(expectedMaxDepth, actualBinding.ReaderQuotas.MaxDepth);
            }
        }
示例#6
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);
        }