问题
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