http://s.click.taobao.com/t_8?e=7HZ5x%2BOzcB8%2BJwychFYWb7c0dSg%3D&p=mm_11626924_0_0
做了一个测试, 新建一个WebApplication项目, 分别添加 aspx page, asmx web service, WCF service(.svc), 针对每个请求的HttpContext.Current做观察, 结果如下:
Item HttpContext.Current HttpContext.Current.Session
aspx Page: Y Y
asmx web service Y N
WCF service N N
针对上述结论, 在http://www.cnblogs.com/artech/archive/2009/06/24/1510497.html文章中[二、ASP.NET并行(Side by Side)模式]部分有提到, 在WCF寄宿在IIS的环境中, 当aspnet_isapi接收到client 的request之后,会被WCF 的处理程序直接截获,并不会执行aspx页面默认的执行管道, 因此在WCF hosting IIS的环境中是得到的HttpContext.Current永远是null的.
那我们有没有办法使在WCF hosting IIS的环境中使HttpContext.Current不为NULL, 能为我们所用呢?
经过测试发现只要注意下面亮点就可以了:
1. 在hosting WCF的web.config中加入:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
2. 在每个Service的定义(注意不是Contract, 不过就算加在Contract上编译是也会报错)上加上下面Attribute:
[AspNetCompatibilityrequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
再测试看看, 发现WCF hosting IIS的程序中也可以使用HttpContext.Current了.
PS:
NHibernate WCF中Session的问题其实也就可以解决了
分享到:
相关推荐
Artech.WCFService例子
You will start off by creating, implementing, and hosting a basic HelloWorld WCF Service followed by deploying the service and publishing it to IIS. Next, you will learn how to create and test a ...
WCF全面解析 上册.pdf WCF全面解析 上册.pdf WCF全面解析 上册.pdf
[WCF服务编程].(Programming.WCF.Services).Juval.Lowy.文字版.pdf.7z
silverlight+wcf仓库管理源码.rarsilverlight+wcf仓库管理源码.rarsilverlight+wcf仓库管理源码.rarsilverlight+wcf仓库管理源码.rar
关于WCF学习的简单应用,已知的我们的WCF程序宿主是发布到IIS上面的。不过这样不便于我们进行“开始”或“停止”WCF服务的操作。所以尝试了编写以窗体应用程序和控制台程序作为WCF服务宿主的方式。代码中主要提供了...
You will be guided to create six WCF and Entity Framework solutions from scratch, of which three are multi-layered real-world WCF service solutions, so you will not only be reading, but also be ...
WCF高级编程源码.rar 不收资源分,欢迎下载
uploadimage service(WCF) for all platfrom
WCF全面解析 下册.pdf
wcf视频教程2.part1
Written by Microsoft software legend Juval Lowy, Programming WCF Services is the authoritative introduction to Microsoft's new, and some say revolutionary, unified ... It's the Rosetta Stone of WCF.
《WCF揭密》分两个压缩包 《WCF揭密》.part1.rar 《WCF揭密》.part2.rar 请分别下载。
artech.wcfservice WCF 例子
Programming WCF Services is the authoritative, bestselling guide to Microsoft's unified platform for developing modern service-oriented applications on Windows. Hailed as the definitive treatment of ...
C# wcf服务实例,源程序,没得错。可能运行通过。
《WCF揭密》分两个压缩包 《WCF揭密》.part1.rar 《WCF揭密》.part2.rar 请分别下载。
wcf视频教程1.part1 讲得很不错,分享给大家。
很不错的学习wcf的教程,讲的很深入,WCF服务编程01.pdf