private Binding ConfigureHttpBinding(ServiceContractConfig config)
        {
            var isStreaming = config.TransferMode.HasValue && config.TransferMode != TransferMode.Buffered;

            if (isStreaming) // WsHttpBinding does not support streaming
            {
                var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                binding.MaxReceivedMessageSize = config.MaxReceivedMessageSize;
                binding.MaxBufferPoolSize      = config.MaxBufferPoolSize;
                binding.UseDefaultWebProxy     = _useDefaultWebProxy;
                binding.ProxyAddress           = _proxyAddress != null ? new Uri(_proxyAddress) : null;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                binding.TransferMode = config.TransferMode.Value;

                return(binding);
            }
            else
            {
                var binding = new WSHttpBinding(SecurityMode.Transport);
                binding.MaxReceivedMessageSize = config.MaxReceivedMessageSize;
                binding.MaxBufferPoolSize      = config.MaxBufferPoolSize;
                binding.UseDefaultWebProxy     = _useDefaultWebProxy;
                binding.ProxyAddress           = _proxyAddress != null ? new Uri(_proxyAddress) : null;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

                return(binding);
            }
        }
        private Binding CreateBinding(ServiceContractConfig config)
        {
            var binding = _transport == Transport.Https ? ConfigureHttpBinding(config) : ConfigureNetTcpBinding(config);

            binding.ReceiveTimeout = config.ReceiveTimeout;
            binding.SendTimeout    = config.SendTimeout;
            binding.OpenTimeout    = config.OpenTimeout;
            binding.CloseTimeout   = config.CloseTimeout;

            return(binding);
        }
        private NetTcpBinding ConfigureNetTcpBinding(ServiceContractConfig config)
        {
            var binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential);

            binding.MaxReceivedMessageSize = config.MaxReceivedMessageSize;
            binding.MaxBufferPoolSize      = config.MaxBufferPoolSize;
            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
            binding.Security.Message.ClientCredentialType   = MessageCredentialType.UserName;

            if (config.TransferMode.HasValue)
            {
                binding.TransferMode = config.TransferMode.Value;
            }

            return(binding);
        }
        private string GetEndpointAddress(ServiceContractConfig config, string pathOverride)
        {
            var path = pathOverride ?? config.Path;

            if (_transport == Transport.NetTcp)
            {
                return($"net.tcp://{_hostname}:{_port ?? 9876}{path}");
            }

            if (_transport == Transport.Https)
            {
                return($"https://{_hostname}:{_port ?? 443}{path}");
            }

            throw new ArgumentException($"Ukjent transport \"{_transport}\"");
        }
 /// <summary>
 /// Legger til WCF konfigurasjon for en servicekontrakt.
 /// </summary>
 /// <param name="nameOfType">Navn på typen til servicekontrakten.</param>
 /// <param name="config">Config-objekt som inneholder WCF-instillinger som skal gjelde for servicekontrakten.</param>
 public void AddKnownConfig(string nameOfType, ServiceContractConfig config)
 {
     _serviceContractConfigs.Add(nameOfType, config);
 }
 /// <summary>
 /// Legger til WCF konfigurasjon for en servicekontrakt.
 /// </summary>
 /// <typeparam name="T">Typen til servicekontrakten.</typeparam>
 /// <param name="config">Config-objekt som inneholder WCF-instillinger som skal gjelde for servicekontrakten.</param>
 public void AddKnownConfig <T>(ServiceContractConfig config)
 {
     AddKnownConfig(typeof(T).Name, config);
 }