سؤال

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?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top