HttpContext.Current is null after waiting in .NET 4.5

I have the following simple WCF service defined in a .NET 4.5 web application:

[ServiceContract] public interface IService1 { [OperationContract] [WebGet(UriTemplate = "json/DoWork/", ResponseFormat = WebMessageFormat.Json)] Task<string> DoWork(); } public class Service1 : IService1 { public async Task<string> DoWork() { Debug.WriteLine(HttpContext.Current != null); var s = await new HttpClient().GetStringAsync("http://www.google.com"); Debug.WriteLine(HttpContext.Current != null); return s; } } 

And web.config:

 <configuration> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <system.serviceModel> <services> <service name="WebApplication1.Service1"> <endpoint address="" binding="webHttpBinding" contract="WebApplication1.IService1"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name=""> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> </configuration> 

Output signal

 True False 

Shouldn't the context be accessible after waiting in .NET 4.5?

+5
source share

Source: https://habr.com/ru/post/1209003/


All Articles