Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpContext is null in WCF service running in ASP.NET Compatibility Mode
    primarykey
    data
    text
    <p>I have a asp.net website that is hosting a WCF service. This service is then accessed from a desktop app. In my service the HttpContext is always null during the execution of the Validate method in my implementation of the UserNamePasswordValidator class. I'm using Username as the client credential type. I need access to the http context in order to get the Url the service was accessed from in order to validate the username and password correctly as the site can be accessed using different Urls and each one has a different user store.</p> <p>The following attribute on the class that contains the method that will be called after the validator class (and the validator class as well)</p> <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] </code></pre> <p>I have a service is configured as follows:</p> <pre><code>&lt;system.serviceModel&gt; &lt;bindings&gt; &lt;wsHttpBinding&gt; &lt;binding name="wsHttpSecurityOptions"&gt; &lt;security mode="Message"&gt; &lt;message clientCredentialType="UserName" establishSecurityContext="true" negotiateServiceCredential="true"/&gt; &lt;transport clientCredentialType="Certificate" proxyCredentialType="None"/&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/wsHttpBinding&gt; &lt;/bindings&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="SecurityServiceBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt; &lt;serviceCredentials&gt; &lt;userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WCFServer.MyAuthenticator" includeWindowsGroups="false"/&gt; &lt;serviceCertificate findValue="myurl.com" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/&gt; &lt;/serviceCredentials&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;services&gt; &lt;service behaviorConfiguration="SecurityServiceBehavior" name="Test.WCF.Actions"&gt; &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpSecurityOptions" contract="WCFServer.IActions"/&gt; &lt;/service&gt; &lt;/services&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt; &lt;/system.serviceModel&gt; </code></pre> <p>I've seen the <a href="http://connect.microsoft.com/wcf/feedback/details/491844/when-using-asp-net-compatibility-mode-httpcontext-and-web-configs-arent-handled-properly-on-the-first-hit-only" rel="nofollow">HttpContext is not initialised on first call bug</a> but this happens to me for every call I make to the service, even when I call the same method on the same connection more than once</p> <p>Edit: clarified question to answer marc_s's comment and Aliostad's question</p> <p>Edit: Added following links that suggest the http context should not be null</p> <ul> <li><a href="http://blogs.msdn.com/b/wenlong/archive/2006/01/23/516041.aspx" rel="nofollow">http://blogs.msdn.com/b/wenlong/archive/2006/01/23/516041.aspx</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/aa702682%28v=VS.90%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa702682(v=VS.90).aspx</a></li> </ul> <p>Can anyone lend me a hand with this please? I'd rather not have to put the site's Url in the appSettings config section for all my sites.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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