URL mapping with C# HttpListener

You can get a similar effect without attributes HttpListener listener = new HttpListener(); listener.Prefixes.Add(“http://*:8080/”); listener.Start(); while (true) { HttpListenerContext ctx = listener.GetContext(); ThreadPool.QueueUserWorkItem((_) => { string methodName = ctx.Request.Url.Segments[1].Replace(“https://stackoverflow.com/”, “”); string[] strParams = ctx.Request.Url .Segments .Skip(2) .Select(s=>s.Replace(“https://stackoverflow.com/”,””)) .ToArray(); var method = this.GetType().GetMethod(methodName); object[] @params = method.GetParameters() .Select((p, i) => Convert.ChangeType(strParams[i], p.ParameterType)) .ToArray(); object ret = … Read more