Пример #1
0
    public static void ClientCredentialType_Property_Sets(TcpClientCredentialType credentialType)
    {
        TcpTransportSecurity transport = new TcpTransportSecurity();

        transport.ClientCredentialType = credentialType;
        Assert.Equal <TcpClientCredentialType>(credentialType, transport.ClientCredentialType);
    }
Пример #2
0
    public static void Ctor_Default_Properties()
    {
        // new TcpTransportSecurity() initializes correct defaults
        TcpTransportSecurity transport = new TcpTransportSecurity();

        Assert.True(transport.ClientCredentialType == TcpClientCredentialType.Windows,
                    String.Format("ClientCredentialType should have been '{0}' but was '{1}'", TcpClientCredentialType.Windows, transport.ClientCredentialType));
    }
Пример #3
0
    public static void Transport_Property_Sets()
    {
        NetTcpSecurity security = new NetTcpSecurity();

        TcpTransportSecurity newSecurity = new TcpTransportSecurity();

        security.Transport = newSecurity;
        Assert.Equal <TcpTransportSecurity>(newSecurity, security.Transport);
    }
 internal void InitializeFrom(TcpTransportSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     this.ClientCredentialType = security.ClientCredentialType;
     this.ProtectionLevel      = security.ProtectionLevel;
     ChannelBindingUtility.InitializeFrom(security.ExtendedProtectionPolicy, this.ExtendedProtectionPolicy);
 }
 internal void ApplyConfiguration(TcpTransportSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     security.ClientCredentialType     = this.ClientCredentialType;
     security.ProtectionLevel          = this.ProtectionLevel;
     security.ExtendedProtectionPolicy = ChannelBindingUtility.BuildPolicy(this.ExtendedProtectionPolicy);
 }
 internal void InitializeFrom(TcpTransportSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ClientCredentialType, security.ClientCredentialType);
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ProtectionLevel, security.ProtectionLevel);
     ChannelBindingUtility.InitializeFrom(security.ExtendedProtectionPolicy, this.ExtendedProtectionPolicy);
 }
Пример #7
0
        public static void Main()
        {
            // <Snippet0>
            using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
            {
                serviceHost.Open();
                ServiceEndpointCollection endpoints = serviceHost.Description.Endpoints;
                ServiceEndpoint           endpoint  = endpoints.Find(typeof(ICalculator));

                NetTcpBinding binding = (NetTcpBinding)endpoint.Binding;

                // <Snippet1>
                NetTcpSecurity         security = binding.Security;
                MessageSecurityOverTcp msTcp    = security.Message;

                Console.WriteLine("Dumping NetTcpSecurity object:");
                Console.WriteLine("\tMessageSecurityOverTcp:");
                Console.WriteLine("\t\tAlgorithm Suite: {0}", msTcp.AlgorithmSuite);
                Console.WriteLine("\t\tClient Credential Type: {0}", msTcp.ClientCredentialType);
                // </Snippet1>

                Console.WriteLine("\tSecurity Mode: {0}", security.Mode);

                // <Snippet3>
                TcpTransportSecurity tsTcp = security.Transport;
                Console.WriteLine("\tTcpTransportSecurity:");
                Console.WriteLine("\t\tClient Credential Type: {0}", tsTcp.ClientCredentialType);
                Console.WriteLine("\t\tProtectionLevel: {0}", tsTcp.ProtectionLevel);
                // </Snippet3>

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();
            }
            // </Snippet0>
        }
Пример #8
0
    public static void ClientCredentialType_Property_Set_Invalid_Value_Throws()
    {
        TcpTransportSecurity transport = new TcpTransportSecurity();

        Assert.Throws <ArgumentOutOfRangeException>(() => transport.ClientCredentialType = (TcpClientCredentialType)999);
    }
Пример #9
0
        public static List <NetTcpBinding> GetNetTcpBindings(string exeConfigPath)
        {
            if (string.IsNullOrWhiteSpace(exeConfigPath))
            {
                return(null);
            }

            var svcSection     = Read.Config.ExeConfig.GetServiceModelSection(exeConfigPath);
            var defaultTimeout = new TimeSpan(0, 0, 60);
            var configs        = new List <NetTcpBinding>();

            foreach (
                var section in
                svcSection.Bindings.NetTcpBinding.ConfiguredBindings
                .Cast <NetTcpBindingElement>())
            {
                var dfltb   = new NetTcpBinding();
                var binding = new NetTcpBinding
                {
                    Name           = section.Name,
                    CloseTimeout   = section.CloseTimeout != TimeSpan.Zero ? section.CloseTimeout : defaultTimeout,
                    OpenTimeout    = section.OpenTimeout != TimeSpan.Zero ? section.OpenTimeout : defaultTimeout,
                    SendTimeout    = section.SendTimeout != TimeSpan.Zero ? section.SendTimeout : defaultTimeout,
                    ReceiveTimeout =
                        section.ReceiveTimeout != TimeSpan.Zero ? section.ReceiveTimeout : defaultTimeout,
                    MaxReceivedMessageSize =
                        section.MaxReceivedMessageSize > 0
                            ? section.MaxReceivedMessageSize
                            : dfltb.MaxReceivedMessageSize,
                    MaxBufferPoolSize =
                        section.MaxBufferPoolSize > 0 ? section.MaxBufferPoolSize : dfltb.MaxBufferPoolSize,
                    MaxConnections = section.MaxConnections > 0 ? section.MaxConnections : dfltb.MaxConnections,

                    ListenBacklog          = section.ListenBacklog > 0 ? section.ListenBacklog : dfltb.ListenBacklog,
                    PortSharingEnabled     = section.PortSharingEnabled,
                    TransactionFlow        = section.TransactionFlow,
                    TransferMode           = section.TransferMode,
                    HostNameComparisonMode = section.HostNameComparisonMode
                };
                var readerQuotasSection = section.ReaderQuotas;
                var readerQuotas        = new System.Xml.XmlDictionaryReaderQuotas();
                if (readerQuotasSection != null && readerQuotasSection.MaxDepth > 0)
                {
                    readerQuotas.MaxDepth = readerQuotasSection.MaxDepth;
                    readerQuotas.MaxStringContentLength = readerQuotasSection.MaxStringContentLength;
                    readerQuotas.MaxArrayLength         = readerQuotasSection.MaxArrayLength;
                    readerQuotas.MaxBytesPerRead        = readerQuotasSection.MaxBytesPerRead;
                    readerQuotas.MaxNameTableCharCount  = readerQuotasSection.MaxNameTableCharCount;
                }
                else
                {
                    readerQuotas = null;
                }
                var netTcpSecurity = new NetTcpSecurity {
                    Mode = section.Security.Mode
                };
                var tcpTransportSecurity = new TcpTransportSecurity();

                var msgSecurityOverTcp = new MessageSecurityOverTcp
                {
                    ClientCredentialType = section.Security.Message.ClientCredentialType,
                    AlgorithmSuite       = section.Security.Message.AlgorithmSuite
                };
                netTcpSecurity.Message   = msgSecurityOverTcp;
                netTcpSecurity.Transport = tcpTransportSecurity;
                binding.Security         = netTcpSecurity;
                if (readerQuotas != null)
                {
                    binding.ReaderQuotas = readerQuotas;
                }
                binding.ReliableSession = new OptionalReliableSession
                {
                    Enabled           = section.ReliableSession.Enabled,
                    InactivityTimeout = section.ReliableSession.InactivityTimeout,
                    Ordered           = section.ReliableSession.Ordered
                };


                configs.Add(binding);
            }
            return(configs);
        }