HttpContext.Current is null in WCF Data Service hosted in Windows Service

家住魔仙堡 提交于 2019-12-11 04:16:42

问题


I created a WCF Data Service inside a Windows Service and tried to access the HttpContext.

I added this to my config file:

 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />   
 </system.serviceModel>

However, when I try to access it, it is null.

protected override void OnStartProcessingRequest(ProcessRequestArgs args)
    {
      base.OnStartProcessingRequest(args);   
      HttpContext httpContext = HttpContext.Current;
      File.AppendAllText(@"c:\Temp\ERROR.log",
      httpContext != null
       ?"HTTPCONTEXT IS NOT NULL"
       :"HTTPCONTEXT IS NULL");
    }

What else should I set?


回答1:


I found the answer, I'm afraid so:

The disabled ASP.NET HTTP features are:

HttpContext.Current: This is always null in this mode. For ASMX services, this is a ThreadStatic property that is stored in the Thread Local Store (TLS). WCF provides a counterpart to this feature: OperationContext.Current.

Source: http://blogs.msdn.com/b/wenlong/archive/2006/01/23/516041.aspx



来源:https://stackoverflow.com/questions/19425649/httpcontext-current-is-null-in-wcf-data-service-hosted-in-windows-service

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