2

我在 Windows 服务中创建了 WCF 数据服务并尝试访问 HttpContext。

我将此添加到我的配置文件中:

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

但是,当我尝试访问它时,它为空。

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");
    }

我还应该设置什么?

4

1 回答 1

1

我找到了答案,恐怕是这样:

禁用的 ASP.NET HTTP 功能包括:

HttpContext.Current:在此模式下始终为 null。对于 ASMX 服务,这是存储在线程本地存储 (TLS) 中的 ThreadStatic 属性。WCF 提供了此功能的对应项:OperationContext.Current。

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

于 2013-10-17T11:50:50.487 回答