CassiniDev源码学习 - 可替代IIS的单机Web Form解决方案
2014-01-22 16:05
267 查看
最近一个项目是将web版的程序,改为单机版。话说这个web版号称当年十几个人用了至少3个月的时间开发,后来三年还不断有修改,而现在要在1个月内由一个人完成,这简直是不可能完成的任务!直觉告诉我,重写肯定不是办法,还好有朋友用过Cassini http://cassinidev.codeplex.com (可替代IIS的单机Web Form解决方案)立即投入测试,可用;有源码,不担心出太大问题。
现在项目结束了,看了一遍CassiniDev,它的基本思路是:
1.新建socket,绑定并监听本机上一个可用的端口。
2.对新建连接(新的请求)创建新的socket。
3.通过一个微软的内部类“System.Web.Compilation.BuildManagerHost”(未对外公布,MSDN查不到),生成Host实例。
4.继承“SimpleWorkerRequest”类(它是System.Web.HttpWorkerRequest 抽象类的简单实现,该抽象类可用于在 Internet 信息服务 (IIS) 应用程序之外承载ASP.NET 应用程序),写一个自己的Request类。
5.由HttpRuntime驱动所有 ASP.NET Web 处理执行。
这个开源组件确实不错,好用,稳定,在winxp, vista, win7, win8都可用。但有一个性能上的不足,在创建微软内部类“System.Web.Compilation.BuildManagerHost”实例时,耗时要5-6秒的时间,机器差一点的话,要9-20秒,目前暂无改进。
现在项目结束了,看了一遍CassiniDev,它的基本思路是:
1.新建socket,绑定并监听本机上一个可用的端口。
2.对新建连接(新的请求)创建新的socket。
public void Start() { _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, _ipAddress, _port); //start the timer //DecrementRequestCount(); ThreadPool.QueueUserWorkItem(delegate { while (!_shutdownInProgress) { try { Socket acceptedSocket = _socket.Accept(); ThreadPool.QueueUserWorkItem(delegate { if (!_shutdownInProgress) { Connection conn = new Connection(this, acceptedSocket); if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); return; } Host host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } //IncrementRequestCount(); host.ProcessRequest(conn); } }); } catch { Thread.Sleep(100); } } }); }
3.通过一个微软的内部类“System.Web.Compilation.BuildManagerHost”(未对外公布,MSDN查不到),生成Host实例。
/// <remarks> /// This is Dmitry's hack to enable running outside of GAC. /// There are some errors being thrown when running in proc /// </remarks> private object CreateWorkerAppDomainWithHost(string virtualPath, string physicalPath, Type hostType,int port) { // create BuildManagerHost in the worker app domain //ApplicationManager appManager = ApplicationManager.GetApplicationManager(); Type buildManagerHostType = typeof(HttpRuntime).Assembly.GetType("System.Web.Compilation.BuildManagerHost"); IRegisteredObject buildManagerHost = ApplicationManager.CreateObject(_appId, buildManagerHostType, virtualPath, physicalPath, false); // call BuildManagerHost.RegisterAssembly to make Host type loadable in the worker app domain buildManagerHostType.InvokeMember("RegisterAssembly", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, buildManagerHost, new object[] { hostType.Assembly.FullName, hostType.Assembly.Location }); // create Host in the worker app domain // FIXME: getting FileLoadException Could not load file or assembly 'WebDev.WebServer20, Version=4.0.1.6, Culture=neutral, PublicKeyToken=f7f6e0b4240c7c27' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418) // when running dnoa 3.4 samples - webdev is registering trust somewhere that we are not return ApplicationManager.CreateObject(_appId, hostType, virtualPath, physicalPath, false); }
4.继承“SimpleWorkerRequest”类(它是System.Web.HttpWorkerRequest 抽象类的简单实现,该抽象类可用于在 Internet 信息服务 (IIS) 应用程序之外承载ASP.NET 应用程序),写一个自己的Request类。
5.由HttpRuntime驱动所有 ASP.NET Web 处理执行。
HttpRuntime.ProcessRequest(this);
这个开源组件确实不错,好用,稳定,在winxp, vista, win7, win8都可用。但有一个性能上的不足,在创建微软内部类“System.Web.Compilation.BuildManagerHost”实例时,耗时要5-6秒的时间,机器差一点的话,要9-20秒,目前暂无改进。
相关文章推荐
- CassiniDev源码学习 - 可替代IIS的单机Web Form解决方案
- 【Python学习笔记】pip安装失败的替代方法&解决方案
- libevent库源码学习-poll/select( linux) .devpoll(/dev/poll)( linux) ,epoll(linux)
- IIS 配置过程及解决方案 学习小结
- VTK观察者和picker学习--从源码中找解决方案
- 用户"IIS APPPOOL\xxxxxxxx"登录失败解决方案(转学习)
- 微软IIS替代解决方案 方配网站服务器
- 学习日记-阿里云云服务器 window iis+php 环境配置解决方案
- 【30分钟学习】二种简单实用的方法实现多语言解决方案(源码在附件)
- 【spring源码学习】spring的aop目标对象中进行自我调用,且需要实施相应的事务定义的解决方案
- 微软IIS替代解决方案 方配网站服务器
- spring源码学习之:项目公共配置项解决方案
- libevent库源码学习-devpoll(/dev/poll)( linux)
- jQuery源码学习笔记三(转)
- Dynamic CRM 2015学习笔记(5)CRM 2015 导入 OData Query Designer 解决方案
- [源码学习][知了开发]WebMagic-CountableThreadPool&SpiderMonitor
- Asp.net core 学习笔记 ( IIS, static file 性能优化 )
- spark1.5.1源码学习初探
- JDK并发工具类源码学习系列——ConcurrentSkipListMap(续)
- Struts源码学习之ActionServlet(二)