Esempio n. 1
0
        private static NetTcpBinding getBinding(PropertyString connectionProperties, out bool isWindowsCredential)
        {
            SecurityMode  securityMode = connectionProperties.GetEnum <SecurityMode>("SecurityMode", true);
            NetTcpBinding binding      = new NetTcpBinding(securityMode, false);

            binding.OpenTimeout            = connectionProperties.GetOptional("OpenTimeout", TimeSpan.FromSeconds(defaultTimeoutSeconds));
            binding.CloseTimeout           = connectionProperties.GetOptional("CloseTimeout", TimeSpan.FromSeconds(defaultTimeoutSeconds));
            binding.ReceiveTimeout         = connectionProperties.GetOptional("RecieveTimeout", TimeSpan.FromSeconds(defaultTimeoutSeconds));
            binding.SendTimeout            = connectionProperties.GetOptional("SendTimeout", TimeSpan.FromSeconds(defaultTimeoutSeconds));
            binding.MaxReceivedMessageSize = connectionProperties.GetOptional("MaxReceivedMessageSize", defaultMaxReceivedMessageSize);
            binding.MaxBufferSize          = connectionProperties.GetOptional("MaxBufferSize", defaultMaxBufferSize);
            binding.ReaderQuotas.MaxStringContentLength = connectionProperties.GetOptional("MaxStringContentLength", defaultMaxStringContentLength);
            binding.ReaderQuotas.MaxArrayLength         = connectionProperties.GetOptional("MaxArrayLength", defaultMaxArrayLength);
            binding.ReaderQuotas.MaxBytesPerRead        = connectionProperties.GetOptional("MaxBytesPerRead", defaultMaxBytesPerRead);
            switch (securityMode)
            {
            case SecurityMode.Message:
                binding.Security.Message.ClientCredentialType = connectionProperties.GetEnum <MessageCredentialType>("MessageCredentialType", false);
                isWindowsCredential = binding.Security.Message.ClientCredentialType == MessageCredentialType.Windows;
                break;

            case SecurityMode.Transport:
                binding.Security.Transport.ClientCredentialType = connectionProperties.GetEnum <TcpClientCredentialType>("ClientCredentialType", false);
                isWindowsCredential = binding.Security.Transport.ClientCredentialType == TcpClientCredentialType.Windows;
                break;

            default:
                isWindowsCredential = false;
                break;
            }
            return(binding);
        }
Esempio n. 2
0
 private static void setupFactory(ChannelFactory factory, PropertyString connectionProperties, bool isWindowsCredential)
 {
     if (isWindowsCredential)
     {
         bool allowNtml = connectionProperties.GetOptional("AllowNtml", true);
         factory.Credentials.Windows.AllowNtlm = connectionProperties.GetOptional("AllowNtlm", allowNtml);
     }
     System.Security.Principal.TokenImpersonationLevel tokenImpersonationLevel;
     if (!connectionProperties.GetEnum <System.Security.Principal.TokenImpersonationLevel>("TokenImpersonationLevel", out tokenImpersonationLevel))
     {
         tokenImpersonationLevel = isWindowsCredential ?
                                   System.Security.Principal.TokenImpersonationLevel.Impersonation : System.Security.Principal.TokenImpersonationLevel.None;
     }
     factory.Credentials.Windows.AllowedImpersonationLevel = tokenImpersonationLevel;
 }