diff --git a/WebListener.sln b/WebListener.sln index 1037bd9799..e8e84a23e0 100644 --- a/WebListener.sln +++ b/WebListener.sln @@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Security.W EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Server.WebListener.FunctionalTests.net45", "test\Microsoft.AspNet.Server.WebListener.FunctionalTests\Microsoft.AspNet.Server.WebListener.FunctionalTests.net45.csproj", "{E7841BDA-EEE0-42D8-8E09-48F021B1934E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfHostServer.k10", "samples\SelfHostServer\SelfHostServer.k10.csproj", "{990662B2-A857-4DD6-85F3-F8517ACAAB13}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -75,6 +77,10 @@ Global {E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Release|Any CPU.ActiveCfg = Release|Any CPU {E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Release|Any CPU.Build.0 = Release|Any CPU + {990662B2-A857-4DD6-85F3-F8517ACAAB13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {990662B2-A857-4DD6-85F3-F8517ACAAB13}.Debug|Any CPU.Build.0 = Debug|Any CPU + {990662B2-A857-4DD6-85F3-F8517ACAAB13}.Release|Any CPU.ActiveCfg = Release|Any CPU + {990662B2-A857-4DD6-85F3-F8517ACAAB13}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -90,5 +96,6 @@ Global {8B4EF749-251D-4222-AD18-DE5A1E7D321A} = {99D5E5F3-88F5-4CCF-8D8C-717C8925DF09} {3EC418D5-C8FD-47AA-BFED-F524358EC3DD} = {E183C826-1360-4DFF-9994-F33CED5C8525} {E7841BDA-EEE0-42D8-8E09-48F021B1934E} = {E183C826-1360-4DFF-9994-F33CED5C8525} + {990662B2-A857-4DD6-85F3-F8517ACAAB13} = {3A1E31E3-2794-4CA3-B8E2-253E96BDE514} EndGlobalSection EndGlobal diff --git a/samples/SelfHostServer/Program.cs b/samples/SelfHostServer/Program.cs deleted file mode 100644 index f01efdd682..0000000000 --- a/samples/SelfHostServer/Program.cs +++ /dev/null @@ -1,138 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ----------------------------------------------------------------------- - -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Owin; -using Microsoft.AspNet.Server.WebListener; -using Microsoft.Owin.Hosting; -using Owin; - -namespace SelfHostServer -{ - // http://owin.org/extensions/owin-WebSocket-Extension-v0.4.0.htm - using WebSocketAccept = Action, // options - Func, Task>>; // callback - using WebSocketCloseAsync = - Func; - using WebSocketReceiveAsync = - Func /* data */, - CancellationToken /* cancel */, - Task>>; - using WebSocketReceiveResult = Tuple; // count - using WebSocketSendAsync = - Func /* data */, - int /* messageType */, - bool /* endOfMessage */, - CancellationToken /* cancel */, - Task>; - - public class Program - { - private static byte[] Data = new byte[1024]; - - public static void Main(string[] args) - { - using (WebApp.Start(new StartOptions( - // "http://localhost:5000/" - "https://localhost:9090/" - ) - { - ServerFactory = "Microsoft.AspNet.Server.WebListener" - })) - { - Console.WriteLine("Running, press any key to exit"); - // System.Diagnostics.Process.Start("http://localhost:5000/"); - Console.ReadKey(); - } - } - - public void Configuration(IAppBuilder app) - { - OwinWebListener listener = (OwinWebListener)app.Properties["Microsoft.AspNet.Server.WebListener.OwinWebListener"]; - listener.AuthenticationManager.AuthenticationTypes = - AuthenticationType.Basic | - AuthenticationType.Digest | - AuthenticationType.Negotiate | - AuthenticationType.Ntlm | - AuthenticationType.Kerberos; - - app.Use((context, next) => - { - Console.WriteLine("Request: " + context.Request.Uri); - return next(); - }); - app.Use((context, next) => - { - if (context.Request.User == null) - { - context.Response.StatusCode = 401; - return Task.FromResult(0); - } - else - { - Console.WriteLine(context.Request.User.Identity.AuthenticationType); - } - return next(); - }); - app.UseWebSockets(); - app.Use(UpgradeToWebSockets); - app.Run(Invoke); - } - - public Task Invoke(IOwinContext context) - { - context.Response.ContentLength = Data.Length; - return context.Response.WriteAsync(Data); - } - - // Run once per request - private Task UpgradeToWebSockets(IOwinContext context, Func next) - { - WebSocketAccept accept = context.Get("websocket.Accept"); - if (accept == null) - { - // Not a websocket request - return next(); - } - - accept(null, WebSocketEcho); - - return Task.FromResult(null); - } - - private async Task WebSocketEcho(IDictionary websocketContext) - { - var sendAsync = (WebSocketSendAsync)websocketContext["websocket.SendAsync"]; - var receiveAsync = (WebSocketReceiveAsync)websocketContext["websocket.ReceiveAsync"]; - var closeAsync = (WebSocketCloseAsync)websocketContext["websocket.CloseAsync"]; - var callCancelled = (CancellationToken)websocketContext["websocket.CallCancelled"]; - - byte[] buffer = new byte[1024]; - WebSocketReceiveResult received = await receiveAsync(new ArraySegment(buffer), callCancelled); - - object status; - while (!websocketContext.TryGetValue("websocket.ClientCloseStatus", out status) || (int)status == 0) - { - // Echo anything we receive - await sendAsync(new ArraySegment(buffer, 0, received.Item3), received.Item1, received.Item2, callCancelled); - - received = await receiveAsync(new ArraySegment(buffer), callCancelled); - } - - await closeAsync((int)websocketContext["websocket.ClientCloseStatus"], (string)websocketContext["websocket.ClientCloseDescription"], callCancelled); - } - } -} diff --git a/samples/SelfHostServer/Startup.cs b/samples/SelfHostServer/Startup.cs new file mode 100644 index 0000000000..163ce335a6 --- /dev/null +++ b/samples/SelfHostServer/Startup.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Server.WebListener; + +namespace SelfHostServer +{ + public class Startup + { + public void Configuration(IBuilder app) + { + var info = (ServerInformation)app.Server; + info.Listener.AuthenticationManager.AuthenticationTypes = AuthenticationType.None; + + app.Run(async context => + { + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync("Hello world"); + }); + } + } +} diff --git a/samples/SelfHostServer/project.json b/samples/SelfHostServer/project.json index ed203d2aeb..4caf1e1901 100644 --- a/samples/SelfHostServer/project.json +++ b/samples/SelfHostServer/project.json @@ -1,19 +1,33 @@ { "version" : "0.1-alpha-*", "dependencies": { - "Microsoft.AspNet.Server.WebListener" : "", - "Microsoft.AspNet.WebSockets" : "" + "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.Hosting": "0.1-alpha-*", + "Microsoft.AspNet.Server.WebListener": "" }, + "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "configurations": { "net45": { + }, + "k10": { "dependencies": { - "Owin": "1.0", - "Microsoft.Owin": "2.1.0", - "Microsoft.Owin.Diagnostics": "2.1.0", - "Microsoft.Owin.Hosting": "2.1.0", - "Microsoft.Owin.Host.HttpListener": "2.1.0", - "Microsoft.AspNet.AppBuilderSupport": "0.1-alpha-*" - } + "System.Console": "4.0.0.0", + "System.Collections": "4.0.0.0", + "System.Diagnostics.Debug": "4.0.10.0", + "System.Diagnostics.Tools": "4.0.0.0", + "System.Globalization": "4.0.10.0", + "System.IO": "4.0.0.0", + "System.IO.FileSystem": "4.0.0.0", + "System.IO.FileSystem.Primitives": "4.0.0.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Resources.ResourceManager": "4.0.0.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Runtime.InteropServices": "4.0.10.0", + "System.Text.Encoding": "4.0.10.0", + "System.Threading.Tasks": "4.0.10.0" + } } } -} +} \ No newline at end of file