public Start ( |
||
address | Address to accept connections on | |
port | int | Port to use. Set to |
Результат | void |
public void work_with_custom_header() { var sut = new HttpListener(); sut.Start(IPAddress.Loopback, 0); var request = WebRequest.CreateHttp("http://localhost:" + sut.LocalPort); request.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return(true); }; request.Headers.Add("SOAPAction", "urn:BVTAFService:PostMessages"); request.ContentType = "text/xml; charset=utf-8"; request.Method = "POST"; var formattedMessage = string.Format(Wrapper, "<fake><soap /></fake>"); var buf = Encoding.UTF8.GetBytes(formattedMessage); request.GetRequestStream().Write(buf, 0, buf.Length); HttpRequestBase msg; sut.MessageReceived += (channel, message) => { msg = (HttpRequestBase)message; channel.Send(msg.CreateResponse()); }; var response = request.GetResponse(); }
static void Main(string[] args) { var certificate = new X509Certificate2("GriffinNetworkingTemp.pfx", "mamma"); var config = new LiteServerConfiguration(); config.Modules.AddAuthentication(new HashAuthenticationModule(new FakeFetcher())); config.Modules.AddAuthorization(new MustAlwaysAuthenticate()); var server = new LiteServer(config); server.Start(IPAddress.Loopback, 0); var client = new CqsClient(() => new DataContractMessageSerializer()); client.Authenticator = new HashClientAuthenticator(new NetworkCredential("jonas", "mamma")); client.StartAsync(IPAddress.Loopback, server.LocalPort).Wait(); client.ExecuteAsync(new HelloWorld()).Wait(); var listener = new HttpListener(); listener.ChannelFactory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certificate)); listener.ClientConnected += OnConnect; listener.MessageReceived = OnMessage; listener.BodyDecoder = new CompositeIMessageSerializer(); listener.Start(IPAddress.Any, 8083); Console.ReadLine(); }
static void Main(string[] args) { var certificate = new X509Certificate2("GriffinNetworkingTemp.pfx", "mamma"); var config = new LiteServerConfiguration(); config.Modules.AddAuthentication(new HashAuthenticationModule(new FakeFetcher())); config.Modules.AddAuthorization(new MustAlwaysAuthenticate()); var server = new LiteServer(config); server.Start(IPAddress.Loopback, 0); var client = new CqsClient(() => new DataContractMessageSerializer()); client.Authenticator = new HashClientAuthenticator(new NetworkCredential("jonas", "mamma")); client.StartAsync(IPAddress.Loopback, server.LocalPort).Wait(); client.ExecuteAsync(new HelloWorld()).Wait(); var listener = new HttpListener(); listener.ChannelFactory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certificate)); listener.ClientConnected += OnConnect; listener.MessageReceived = OnMessage; listener.BodyDecoder = new CompositeIMessageSerializer(); listener.Start(IPAddress.Any, 8083); Console.ReadLine(); }
static void Main(string[] args) { JsonConvert.DefaultSettings = (() => { var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter()); return(settings); }); AddUser(new UserData("root", "root", false)); HttpListener httpServer = new HttpListener(new ChannelTcpListenerConfiguration( () => new HttpMessageDecoder(), () => new HttpMessageEncoder() )); httpServer.ClientConnected += httpServer_ClientConnected; httpServer.MessageReceived = OnMessage; httpServer.Start(IPAddress.Any, 38012); //CLI MENU while (true) { Console.Out.WriteLine("========================================"); Console.Out.WriteLine("Menu:"); Console.Out.WriteLine("1) List users"); Console.Out.WriteLine("2) Add/Edit user"); Console.Out.WriteLine("3) Delete user"); Console.Out.WriteLine("9) Exit program"); Console.Out.Write("Choice: "); string picked = Console.In.ReadLine(); Console.Out.WriteLine("----------------------------------------"); switch (picked) { case "1": foreach (UserData userData in validUsers.Values) { Console.Out.WriteLine("Name: " + userData.name + ", ReadOnly: " + (userData.readOnly ? "Yes" : "No")); } break; case "2": UserData user = ConsoleReadUser(); validUsers[user.name] = user; break; case "3": Console.Out.Write("Username: "******"9": httpServer.Stop(); return; } } }
static void Main(string[] args) { JsonConvert.DefaultSettings = (() => { var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter()); return settings; }); AddUser(new UserData("root", "root", false)); HttpListener httpServer = new HttpListener(new ChannelTcpListenerConfiguration( () => new HttpMessageDecoder(), () => new HttpMessageEncoder() )); httpServer.ClientConnected += httpServer_ClientConnected; httpServer.MessageReceived = OnMessage; httpServer.Start(IPAddress.Any, 38012); //CLI MENU while (true) { Console.Out.WriteLine("========================================"); Console.Out.WriteLine("Menu:"); Console.Out.WriteLine("1) List users"); Console.Out.WriteLine("2) Add/Edit user"); Console.Out.WriteLine("3) Delete user"); Console.Out.WriteLine("9) Exit program"); Console.Out.Write("Choice: "); string picked = Console.In.ReadLine(); Console.Out.WriteLine("----------------------------------------"); switch(picked) { case "1": foreach(UserData userData in validUsers.Values) Console.Out.WriteLine("Name: " + userData.name + ", ReadOnly: " + (userData.readOnly ? "Yes" : "No")); break; case "2": UserData user = ConsoleReadUser(); validUsers[user.name] = user; break; case "3": Console.Out.Write("Username: "******"9": httpServer.Stop(); return; } } }
static void Main(string[] args) { var certificate = new X509Certificate2("GriffinNetworkingTemp.pfx", "mamma"); var listener = new HttpListener(); listener.ChannelFactory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certificate)); listener.ClientConnected += OnConnect; listener.MessageReceived = OnMessage; listener.BodyDecoder = new CompositeBodyDecoder(); listener.Start(IPAddress.Any, 8083); Console.ReadLine(); }
static void Main(string[] args) { var certificate = new X509Certificate2("GriffinNetworkingTemp.pfx", "mamma"); var listener = new HttpListener(); listener.ChannelFactory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certificate)); listener.ClientConnected += OnConnect; listener.MessageReceived = OnMessage; listener.BodyDecoder = new CompositeBodyDecoder(); listener.Start(IPAddress.Any, 8083); Console.ReadLine(); }
/// <summary> /// Start the HTTP server /// </summary> /// <param name="ipAddress">Address to listen on</param> /// <param name="port">Port to listen on.</param> /// <exception cref="System.ArgumentNullException">ipAddress</exception> /// <exception cref="System.InvalidOperationException">Stop the server before restarting.</exception> public void Start(IPAddress ipAddress, int port) { if (ipAddress == null) { throw new ArgumentNullException("ipAddress"); } if (_listener != null) { throw new InvalidOperationException("Stop the server before restarting."); } _listener = new HttpListener(_configuration); _listener.BodyDecoder = BodyDecoder; _listener.MessageReceived = OnClientRequest; _listener.Start(ipAddress, port); }
/// <summary> /// Start the HTTP server /// </summary> /// <param name="ipAddress">Address to listen on</param> /// <param name="port">Port to listen on.</param> /// <example> /// <p>You can load a certificate by doing the following:</p> /// <code> /// var certificate = new X509Certificate2(@"C:\certificates\yourCertificate", "yourpassword"); /// var server = new HttpServer(new ModuleManager()); /// server.Start(IPAddress.Any, 80, certifiate); /// </code> /// </example> public void Start(IPAddress ipAddress, int port, X509Certificate certifiate) { if (ipAddress == null) { throw new ArgumentNullException("ipAddress"); } if (_listener != null) { throw new InvalidOperationException("Stop the server before restarting."); } var factory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certifiate)); _listener = new HttpListener(); _listener.ChannelFactory = factory; _listener.MessageReceived = OnClientRequest; _listener.Start(ipAddress, port); }
public void work_with_custom_header() { var sut = new HttpListener(); sut.Start(IPAddress.Loopback, 0); var request = WebRequest.CreateHttp("http://localhost:" + sut.LocalPort); request.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return true; }; request.Headers.Add("SOAPAction", "urn:BVTAFService:PostMessages"); request.ContentType = "text/xml; charset=utf-8"; request.Method = "POST"; var formattedMessage = string.Format(Wrapper, "<fake><soap /></fake>"); var buf = Encoding.UTF8.GetBytes(formattedMessage); request.GetRequestStream().Write(buf, 0, buf.Length); HttpRequestBase msg; sut.MessageReceived += (channel, message) => { msg = (HttpRequestBase) message; channel.Send(msg.CreateResponse()); }; var response = request.GetResponse(); }
/// <summary> /// Start the HTTP server /// </summary> /// <param name="ipAddress">Address to listen on</param> /// <param name="port">Port to listen on.</param> /// <example> /// <p>You can load a certificate by doing the following:</p> /// <code> /// var certificate = new X509Certificate2(@"C:\certificates\yourCertificate", "yourpassword"); /// var server = new HttpServer(new ModuleManager()); /// server.Start(IPAddress.Any, 80, certifiate); /// </code> /// </example> public void Start(IPAddress ipAddress, int port, X509Certificate certifiate) { if (ipAddress == null) throw new ArgumentNullException("ipAddress"); if (_listener != null) throw new InvalidOperationException("Stop the server before restarting."); var factory=new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certifiate)); _listener = new HttpListener(); _listener.ChannelFactory = factory; _listener.MessageReceived = OnClientRequest; _listener.Start(ipAddress, port); }
/// <summary> /// Start the HTTP server /// </summary> /// <param name="ipAddress">Address to listen on</param> /// <param name="port">Port to listen on.</param> /// <exception cref="System.ArgumentNullException">ipAddress</exception> /// <exception cref="System.InvalidOperationException">Stop the server before restarting.</exception> public void Start(IPAddress ipAddress, int port) { if (ipAddress == null) throw new ArgumentNullException("ipAddress"); if (_listener != null) throw new InvalidOperationException("Stop the server before restarting."); _listener = new HttpListener(_configuration); _listener.BodyDecoder = BodyDecoder; _listener.MessageReceived = OnClientRequest; _listener.Start(ipAddress, port); }
/// <summary> /// Endpoint to listen on. /// </summary> /// <param name="endPoint">The end point.</param> public void Start(IPEndPoint endPoint) { _listener.Start(endPoint.Address, endPoint.Port); _listener.MessageReceived += OnMessage; }
public UploadToCoderrTests() { _listener = new HttpListener(); _listener.Start(IPAddress.Any, 0); _listener.MessageReceived += OnMessage; }