public void DefaultValues () { var n = new NetTcpBinding (); Assert.AreEqual (HostNameComparisonMode.StrongWildcard, n.HostNameComparisonMode, "#1"); Assert.AreEqual (10, n.ListenBacklog, "#2"); Assert.AreEqual (false, n.PortSharingEnabled, "#3"); var tr = n.CreateBindingElements ().Find<TcpTransportBindingElement> (); Assert.IsNotNull (tr, "#tr1"); Assert.AreEqual (false, tr.TeredoEnabled, "#tr2"); Assert.AreEqual ("net.tcp", tr.Scheme, "#tr3"); Assert.IsFalse (n.TransactionFlow, "#4"); var tx = n.CreateBindingElements ().Find<TransactionFlowBindingElement> (); Assert.IsNotNull (tx, "#tx1"); Assert.AreEqual (SecurityMode.Transport, n.Security.Mode, "#sec1"); Assert.AreEqual (ProtectionLevel.EncryptAndSign, n.Security.Transport.ProtectionLevel, "#sec2"); Assert.AreEqual (TcpClientCredentialType.Windows/*huh*/, n.Security.Transport.ClientCredentialType, "#sec3"); var bc = n.CreateBindingElements (); Assert.AreEqual (4, bc.Count, "#bc1"); Assert.AreEqual (typeof (TransactionFlowBindingElement), bc [0].GetType (), "#bc2"); Assert.AreEqual (typeof (BinaryMessageEncodingBindingElement), bc [1].GetType (), "#bc3"); Assert.AreEqual (typeof (WindowsStreamSecurityBindingElement), bc [2].GetType (), "#bc4"); Assert.AreEqual (typeof (TcpTransportBindingElement), bc [3].GetType (), "#bc5"); Assert.IsFalse (n.CanBuildChannelFactory<IRequestChannel> (), "#cbf1"); Assert.IsFalse (n.CanBuildChannelFactory<IOutputChannel> (), "#cbf2"); Assert.IsFalse (n.CanBuildChannelFactory<IDuplexChannel> (), "#cbf3"); Assert.IsTrue (n.CanBuildChannelFactory<IDuplexSessionChannel> (), "#cbf4"); }
public void DefaultValues () { var n = new NetTcpBinding (); Assert.AreEqual (HostNameComparisonMode.StrongWildcard, n.HostNameComparisonMode, "#1"); Assert.AreEqual (10, n.ListenBacklog, "#2"); Assert.AreEqual (false, n.PortSharingEnabled, "#3"); var tr = n.CreateBindingElements ().Find<TcpTransportBindingElement> (); Assert.IsNotNull (tr, "#tr1"); Assert.AreEqual (false, tr.TeredoEnabled, "#tr2"); Assert.AreEqual ("net.tcp", tr.Scheme, "#tr3"); Assert.IsFalse (n.TransactionFlow, "#4"); var tx = n.CreateBindingElements ().Find<TransactionFlowBindingElement> (); Assert.IsNotNull (tx, "#tx1"); }
public void MessageSecurityAndBindings () { var n = new NetTcpBinding (); n.Security.Mode = SecurityMode.Message; Assert.AreEqual (SecurityAlgorithmSuite.Default, n.Security.Message.AlgorithmSuite, "#sec1"); Assert.AreEqual (MessageCredentialType.Windows/*huh*/, n.Security.Message.ClientCredentialType, "#sec2"); Assert.AreEqual (TransferMode.Buffered, n.TransferMode, "#sec3"); var bc = n.CreateBindingElements (); Assert.AreEqual (4, bc.Count, "#bc1"); Assert.AreEqual (typeof (TransactionFlowBindingElement), bc [0].GetType (), "#bc2"); Assert.AreEqual (typeof (SymmetricSecurityBindingElement), bc [1].GetType (), "#bc3"); Assert.AreEqual (typeof (BinaryMessageEncodingBindingElement), bc [2].GetType (), "#bc4"); Assert.AreEqual (typeof (TcpTransportBindingElement), bc [3].GetType (), "#bc5"); Assert.IsFalse (n.CanBuildChannelFactory<IRequestChannel> (), "#cbf1"); Assert.IsFalse (n.CanBuildChannelFactory<IOutputChannel> (), "#cbf2"); Assert.IsFalse (n.CanBuildChannelFactory<IDuplexChannel> (), "#cbf3"); Assert.IsTrue (n.CanBuildChannelFactory<IDuplexSessionChannel> (), "#cbf4"); }
public void MessageSecurityAndBindings4 () { var n = new NetTcpBinding (); n.Security.Mode = SecurityMode.Message; n.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; var bc = n.CreateBindingElements (); Assert.AreEqual (4, bc.Count, "#bc1"); Assert.AreEqual (typeof (TransactionFlowBindingElement), bc [0].GetType (), "#bc2"); Assert.AreEqual (typeof (SymmetricSecurityBindingElement), bc [1].GetType (), "#bc3"); Assert.AreEqual (typeof (BinaryMessageEncodingBindingElement), bc [2].GetType (), "#bc4"); Assert.AreEqual (typeof (TcpTransportBindingElement), bc [3].GetType (), "#bc5"); Assert.IsFalse (n.CanBuildChannelFactory<IRequestChannel> (), "#cbf1"); Assert.IsFalse (n.CanBuildChannelFactory<IOutputChannel> (), "#cbf2"); Assert.IsFalse (n.CanBuildChannelFactory<IDuplexChannel> (), "#cbf3"); Assert.IsTrue (n.CanBuildChannelFactory<IDuplexSessionChannel> (), "#cbf4"); }
/// <summary> /// Gets the WCF service binding for the specified protocol, security mode, and throttle settings. /// </summary> /// <param name="protocol">The protocol.</param> /// <param name="securityMode">The security mode.</param> /// <param name="maxConnections">The max connections.</param> /// <param name="leaseTimeout">The lease timeout.</param> /// <returns>A <see cref="Binding"/> object.</returns> public static Binding GetBinding(BusinessServicesProtocol protocol, SecurityMode? securityMode, int? maxConnections, int? leaseTimeout) { if (protocol == BusinessServicesProtocol.WSHttp) { WSHttpBinding binding = new WSHttpBinding(); binding.Security.Mode = securityMode ?? ConfigSettingsReader.WSHttpWcfSecurityMode(); binding.MaxReceivedMessageSize = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxBytesPerRead = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxDepth = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxArrayLength = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxStringContentLength = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReceiveTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.SendTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.OpenTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.CloseTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.ReliableSession.InactivityTimeout = ConfigSettingsReader.ServicesClientTimeout(); return binding; } else if (protocol == BusinessServicesProtocol.NetTcp) { NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = securityMode ?? ConfigSettingsReader.NetTcpWcfSecurityMode(); binding.MaxReceivedMessageSize = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxBytesPerRead = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxDepth = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxArrayLength = ConfigSettingsReader.MaxSendReceiveSize(); binding.ReaderQuotas.MaxStringContentLength = ConfigSettingsReader.MaxSendReceiveSize(); binding.PortSharingEnabled = ConfigSettingsReader.PortSharingEnabled(); binding.ReceiveTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.SendTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.OpenTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.CloseTimeout = ConfigSettingsReader.ServicesClientTimeout(); binding.ReliableSession.InactivityTimeout = ConfigSettingsReader.ServicesClientTimeout(); if (maxConnections != null) binding.MaxConnections = maxConnections.Value; if (leaseTimeout != null) binding.CreateBindingElements().Find<TcpTransportBindingElement>().ConnectionPoolSettings.LeaseTimeout = new TimeSpan(0, 0, leaseTimeout.Value); return binding; } else { NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); binding.MaxReceivedMessageSize = BusinessServicesConstants.MaxSendReceiveSize; binding.ReaderQuotas.MaxBytesPerRead = BusinessServicesConstants.MaxSendReceiveSize; binding.ReaderQuotas.MaxDepth = BusinessServicesConstants.MaxSendReceiveSize; binding.ReaderQuotas.MaxArrayLength = BusinessServicesConstants.MaxSendReceiveSize; binding.ReaderQuotas.MaxStringContentLength = BusinessServicesConstants.MaxSendReceiveSize; binding.ReceiveTimeout = new TimeSpan(0, BusinessServicesConstants.ServicesClientTimeout, 0); binding.SendTimeout = new TimeSpan(0, BusinessServicesConstants.ServicesClientTimeout, 0); binding.OpenTimeout = new TimeSpan(0, BusinessServicesConstants.ServicesClientTimeout, 0); binding.CloseTimeout = new TimeSpan(0, BusinessServicesConstants.ServicesClientTimeout, 0); if (maxConnections != null) binding.MaxConnections = maxConnections.Value; return binding; } }