Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to host a WCF service inside a asp.net MVC application using AspNetCompatibility so that i could access the HttpContext, i have added the following line to my Web.config under system.serviceModel:

HTML
<servicehostingenvironment aspnetcompatibilityenabled="true"></servicehostingenvironment>


and the following attribute to my service class:

C#
[AspNetCompatibilityRequirements(RequirementsMode= AspNetCompatibilityRequirementsMode.Allowed)]


but the HttpContex.Current is still null, what am i missing?
Posted
Updated 10-Nov-11 3:47am
v2
Comments
RaisKazi 10-Nov-11 9:38am    
I had posted Answer with suggestion - Web.config is case-sensitive, check you have specified it as "aspNetCompatibilityEnabled".

Probably you may have specified it correctly but after "pre" tag it's became as "aspnetcompatibilityenabled". Do check it once in your web.config.
huotari 10-Nov-11 9:51am    
it is specified aspNetCompatibilityEnabled and not aspnetcompatibilityenabled
RaisKazi 10-Nov-11 10:01am    
Yup, I realized it later :), "pre" tag seems to be converting it to small letters.
RaisKazi 10-Nov-11 10:10am    

1 solution

Your exception message states "This service requires ASP.NET compatibility and must be hosted in IIS. Either host the service in IIS with ASP.NET compatibility turned on in web.config or set the AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode property to a value other than Required."

and you've posted:

C#
[AspNetCompatibilityRequirements(RequirementsMode= AspNetCompatibilityRequirementsMode.Required)]


You need to set the value to something other than required.
 
Share this answer
 
Comments
huotari 10-Nov-11 9:31am    
I tried that but then the HttpContext.Current was null

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900