private TlsServer InitializeTlsServer() { TlsServer remotingServer; remotingServer = new TlsServer(); remotingServer.CertificateFile = "Internal.cer"; remotingServer.ConfigurationString = "Port=8500"; remotingServer.IgnoreInvalidCredentials = true; remotingServer.PayloadAware = true; remotingServer.PersistSettings = true; remotingServer.SettingsCategory = "RemotingServer"; remotingServer.TrustedCertificatesPath = $"Certs{Path.DirectorySeparatorChar}Remotes"; remotingServer.Initialize(); remotingServer.RemoteCertificateValidationCallback = (o, certificate, chain, errors) => true; return remotingServer; }
/// <summary> /// Create a communications server /// </summary> /// <remarks> /// Note that typical configuration string should be prefixed with a "protocol=tcp" or a "protocol=udp" /// </remarks> /// <param name="configurationString">The configuration string for the server.</param> /// <returns>A communications server.</returns> public static IServer Create(string configurationString) { Dictionary<string, string> configurationSettings = configurationString.ParseKeyValuePairs(); IServer server; string protocol; if (configurationSettings.TryGetValue("protocol", out protocol)) { configurationSettings.Remove("protocol"); StringBuilder settings = new StringBuilder(); foreach (string key in configurationSettings.Keys) { settings.Append(key); settings.Append("="); settings.Append(configurationSettings[key]); settings.Append(";"); } // Create a server instance for the specified protocol. switch (protocol.Trim().ToLower()) { case "tls": server = new TlsServer(settings.ToString()); break; case "tcp": server = new TcpServer(settings.ToString()); break; case "udp": server = new UdpServer(settings.ToString()); break; case "zeromq": server = new ZeroMQServer(settings.ToString()); break; default: throw new ArgumentException("Transport protocol \'" + protocol + "\' is not valid"); } // Apply server settings from the connection string to the client. foreach (KeyValuePair<string, string> setting in configurationSettings) { PropertyInfo property = server.GetType().GetProperty(setting.Key); if (property != null) property.SetValue(server, Convert.ChangeType(setting.Value, property.PropertyType), null); } } else { throw new ArgumentException("Transport protocol must be specified"); } return server; }