Note that there are some explanatory texts on larger screens.

plurals
  1. POSelf-hosted WCF service has HttpContext.Current == null despite the fact that AspnetCompability allowed
    text
    copied!<p>I'm using self-hosted (programmatically hosted) WCF-service in Web Application. I placed the <code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]</code> attribute to the SampleService class and placed <code>&lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false"/&gt;</code> element to the Web.config in <code>system.serviceModel</code> section. I'm hosting my WCF-service in Global.asax in Application_Start method using next code:</p> <pre><code>protected void Application_Start(object sender, EventArgs e) { var serviceType = typeof (SampleService); var serviceInterfaceType = typeof(ISampleService); var baseAddresses = new Uri(@"https://localhost:443/SilverWIF.WEB/SampleService"); var serviceHost = new ServiceHost(serviceType, baseAddresses); var smb = serviceHost.Description.Behaviors.Find&lt;ServiceMetadataBehavior&gt;(); if (smb == null) { smb = new ServiceMetadataBehavior { HttpsGetEnabled = true }; serviceHost.Description.Behaviors.Add(smb); } else smb.HttpsGetEnabled = true; var sdb = serviceHost.Description.Behaviors.Find&lt;ServiceDebugBehavior&gt;(); if (sdb == null) { sdb = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true }; serviceHost.Description.Behaviors.Add(sdb); } else sdb.IncludeExceptionDetailInFaults = true; serviceHost.Description.Endpoints.Clear(); serviceHost.AddServiceEndpoint(serviceInterfaceType, _getGustomBinding(), string.Empty); serviceHost.Open(); } private static CustomBinding _getGustomBinding() { var binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); var httpsTransportBindingElement = new HttpsTransportBindingElement(); var binding = new CustomBinding(binaryMessageEncodingBindingElement, httpsTransportBindingElement); return binding; } </code></pre> <p>Despite all this, I has HttpContext.Current == null (I'm trying to access it from one of he methods of <code>SampleService</code> class).</p> <p>It is possible to access HttpContext.Current when WCF-service programmatically hosted? Can anybody help me with this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload