gpt4 book ai didi

c# - Windows 服务中托管的 WCF 数据服务中的 HttpContext.Current 为空

转载 作者:太空宇宙 更新时间:2023-11-03 13:33:47 25 4
gpt4 key购买 nike

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

我还应该设置什么?

最佳答案

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

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.

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

关于c# - Windows 服务中托管的 WCF 数据服务中的 HttpContext.Current 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19425649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com