HttpContext in WCF

。_饼干妹妹 提交于 2020-04-29 12:47:48

问题


To use httpContext I changed app.config and added <serviceHostingEnvironment aspNetCompatibilityEnabled="true"> inside <system.serviceModel>.

I also added using System.Web to my implementation class.

Problem is, httpcontext is not available in my implementation class after doing the required steps.

What I am missing?


回答1:


See here: WCF Services and ASP.NET

Within an AppDomain, features implemented by the HTTP runtime apply to ASP.NET content but not to WCF. Many HTTP-specific features of the ASP.NET application platform do not apply to WCF Services hosted inside of an AppDomain that contains ASP.NET content. Examples of these features include the following:

HttpContext: Current is always null when accessed from within a WCF service. Use RequestContext instead.




回答2:


It is possible to access HttpContext in WCF if you set AspNetCompatibility in web.config and on the Service Implementation.

See here.




回答3:


Why don't you use OperationContext? http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontext.aspx



来源:https://stackoverflow.com/questions/5990479/httpcontext-in-wcf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!