コード例 #1
0
        private WSHttpBindingElement CreateWSHttpBinding(string name, SecurityMode mode, HttpClientCredentialType credentialType)
        {
            WSHttpBindingElement wsHttpBinding = new WSHttpBindingElement();

            wsHttpBinding.Name          = name;
            wsHttpBinding.Security.Mode = mode;
            wsHttpBinding.Security.Transport.ClientCredentialType = credentialType;
            return(wsHttpBinding);
        }
コード例 #2
0
        private void ApplyConfiguration(string configurationName)
        {
            WSHttpBindingElement element2 = WSHttpBindingCollectionElement.GetBindingCollectionElement().Bindings[configurationName];

            if (element2 == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidBindingConfigurationName", new object[] { configurationName, "wsHttpBinding" })));
            }
            element2.ApplyConfiguration(this);
        }
コード例 #3
0
        void EnsureBindingRemoved(Configuration config)
        {
            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);

            if (sg.Bindings.WSHttpBinding.Bindings.ContainsKey(this.DefaultBindingName))
            {
                WSHttpBindingElement element = sg.Bindings.WSHttpBinding.Bindings[this.DefaultBindingName];
                sg.Bindings.WSHttpBinding.Bindings.Remove(element);
            }
            if (sg.Bindings.WSHttpBinding.Bindings.ContainsKey(this.DefaultTransactionalBindingName))
            {
                WSHttpBindingElement element = sg.Bindings.WSHttpBinding.Bindings[this.DefaultTransactionalBindingName];
                sg.Bindings.WSHttpBinding.Bindings.Remove(element);
            }
        }
コード例 #4
0
        public void WSHttpBinding()
        {
            ServiceModelSectionGroup config = (ServiceModelSectionGroup)ConfigurationManager.OpenExeConfiguration("Test/config/wsHttpBinding").GetSectionGroup("system.serviceModel");

            WSHttpBindingCollectionElement wsHttpBinding = config.Bindings.WSHttpBinding;

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

            WSHttpBindingElement binding = wsHttpBinding.Bindings [0];

            Assert.AreEqual("WSHttpBinding_IHelloWorldService", binding.Name, "Name");
            Assert.AreEqual(HostNameComparisonMode.StrongWildcard, binding.HostNameComparisonMode, "HostNameComparisonMode");
            Assert.AreEqual(SecurityMode.Message, binding.Security.Mode, "Security.Mode");
            Assert.AreEqual(MessageCredentialType.Windows, binding.Security.Message.ClientCredentialType, "Security.Message.ClientCredentialType");
            Assert.AreEqual(HttpProxyCredentialType.None, binding.Security.Transport.ProxyCredentialType, "Security.Transport.ProtectionLevel");
            Assert.AreEqual(HttpClientCredentialType.Windows, binding.Security.Transport.ClientCredentialType, "Security.Transport.ProtectionLevel");
        }
コード例 #5
0
        void ApplyConfiguration(string configurationName)
        {
            WSHttpBindingCollectionElement section = WSHttpBindingCollectionElement.GetBindingCollectionElement();
            WSHttpBindingElement           element = section.Bindings[configurationName];

            if (element == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
                                                                              SR.GetString(SR.ConfigInvalidBindingConfigurationName,
                                                                                           configurationName,
                                                                                           ConfigurationStrings.WSHttpBindingCollectionElementName)));
            }
            else
            {
                element.ApplyConfiguration(this);
            }
        }
コード例 #6
0
ファイル: SectionGroupTests.cs プロジェクト: komsa-ag/CoreWCF
        public void BindingSection_WithWSHttpBindingTest()
        {
            string       expectedName = "wsHttpBindingConfig";
            long         expectedMaxReceivedMessageSize = 1073741824;
            long         expectedMaxBufferPoolSize      = 1073741824;
            int          expectedMaxDepth       = 2147483647;
            TimeSpan     expectedReceiveTimeout = TimeSpan.FromMinutes(10);
            SecurityMode expectedSecurityMode   = SecurityMode.TransportWithMessageCredential;

            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>
            <wsHttpBinding>
                <binding name=""{expectedName}""
                         maxReceivedMessageSize=""{expectedMaxReceivedMessageSize}""
                         maxBufferPoolSize=""{expectedMaxBufferPoolSize}""
                         receiveTimeout=""{expectedReceiveTimeout}"">
                    <security mode=""{expectedSecurityMode}""/>      
                    <readerQuotas maxDepth=""{expectedMaxDepth}""/>
                </binding>
            </wsHttpBinding>           
        </bindings>                             
    </system.serviceModel>
</configuration>";

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

                WSHttpBindingElement actualBinding = section.Bindings.WSHttpBinding.Bindings.Cast <WSHttpBindingElement>().First();

                Assert.Equal(expectedName, actualBinding.Name);
                Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize);
                Assert.Equal(expectedMaxBufferPoolSize, actualBinding.MaxBufferPoolSize);
                Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout);
                Assert.Equal(expectedSecurityMode, actualBinding.Security.Mode);
                Assert.Equal(expectedMaxDepth, actualBinding.ReaderQuotas.MaxDepth);
            }
        }
コード例 #7
0
        void EnsureWSProfileBindingAdded(Configuration config)
        {
            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);

            if (!sg.Bindings.WSHttpBinding.Bindings.ContainsKey(this.DefaultBindingName))
            {
                WSHttpBindingElement bindingConfig = new WSHttpBindingElement(this.DefaultBindingName);
                bindingConfig.ReliableSession.Enabled = true;
                sg.Bindings.WSHttpBinding.Bindings.Add(bindingConfig);
            }
            if (!sg.Bindings.WSHttpBinding.Bindings.ContainsKey(this.DefaultTransactionalBindingName))
            {
                WSHttpBindingElement bindingConfig = new WSHttpBindingElement(this.DefaultTransactionalBindingName);
                bindingConfig.ReliableSession.Enabled = true;
                bindingConfig.TransactionFlow         = true;
                sg.Bindings.WSHttpBinding.Bindings.Add(bindingConfig);
            }
        }
コード例 #8
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);
        }
コード例 #9
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);
        }