private static void ListenOnAddress(string ip, int port, string appPoolName) { var skt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); skt.Bind(new IPEndPoint(IPAddress.Parse(ip), port)); skt.Listen(10); var appPoolService = new ApplicationPoolService(); while (true) { var proxSkt = skt.Accept(); var buffer = new byte[1024 * 1024 * 2];//In Real IIS, this should be configable var length = proxSkt.Receive(buffer, 0, buffer.Length, SocketFlags.None); var requestText = Encoding.UTF8.GetString(buffer, 0, length); log.Info($"W3SVC Received Http Request on IP {ip}, Port {port}"); Console.WriteLine(requestText); //In Real IIS, HTTP.sys would check if the request has cache, if yes, send back cached response directly log.Info($"Get worker process for apppool {appPoolName}"); var workerProcess = appPoolService.GetWorkerProcessFromAppPool(appPoolName); //A key point that IIS document does not specify is that how W3Svc will handle that sending message to worker process //The reason why it is w3svc sending request to worker process instead of WAS is that WAS can hold other applcation like WCF //So WAS should not coupled with a specific request format(such as HTTP) //That's why w3svc send the request to worker process //May be in other scenario, such as WCF, a WCF message receiver would use WAS to manage its WCF worker process, and WCF message receiver send message to WCF Worker process just like w3svc handles http request SendRequestToWorkerProcess(requestText, workerProcess, response => { proxSkt.Send(Encoding.UTF8.GetBytes(response)); proxSkt.Shutdown(SocketShutdown.Both); proxSkt.Close(); }); } }
public ActionResult Edit(WebsiteViewModel viewModel, int?page) { if (ModelState.IsValid) { var website = AutoMapper.Mapper.Map <WebsiteViewModel, IWebsite>(viewModel); if (viewModel.SelectedPackageConfigurationId > 0) { website.PackageConfiguration = PackageConfigurationService.GetById(viewModel.SelectedPackageConfigurationId); var appPool = AutoMapper.Mapper.Map <ApplicationPoolViewModel, IApplicationPool>(viewModel.ApplicationPool as ApplicationPoolViewModel); website.ApplicationPool = ApplicationPoolService.CreateOrUpdate(appPool); } WebsiteService.CreateOrUpdate(website); } else { viewModel.PackageConfigurations = PackageConfigurationService.GetAll().ToList(); return(View(viewModel)); } return(RedirectToAction("Index")); }