using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsServiceClient { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Start(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } private static void Start() { HttpListener httpListenner; httpListenner = new HttpListener(); httpListenner.AuthenticationSchemes = AuthenticationSchemes.Anonymous; httpListenner.Prefixes.Add("http://localhost:4033/"); httpListenner.Start(); new Thread(new ThreadStart(delegate { try { loop(httpListenner); httpListenner.Stop(); } catch (Exception ex) { var ddd = ex.Message; httpListenner.Stop(); } })).Start(); } private static void loop(HttpListener httpListenner) { while (true) { HttpListenerContext context = httpListenner.GetContext(); HttpListenerRequest request = context.Request; HttpListenerResponse response = context.Response; Servlet servlet = new MyServlet(); servlet.onCreate(); if (request.HttpMethod == "POST") { servlet.onPost(request, response); } else if (request.HttpMethod == "GET") { servlet.onGet(request, response); } response.Close(); } } } }