Click here to Skip to main content
12,997,210 members (76,005 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to host a WCF service inside a MVC application using AspNetCompatibility so that i could access the HttpContext, i have added the following line to my Web.config under system.serviceModel:

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

and the following attribute to my service class:

[AspNetCompatibilityRequirements(RequirementsMode= AspNetCompatibilityRequirementsMode.Allowed)]

but the HttpContex.Current is still null, what am i missing?
Posted 10-Nov-11 3:21am
Updated 10-Nov-11 3:47am
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:

[AspNetCompatibilityRequirements(RequirementsMode= AspNetCompatibilityRequirementsMode.Required)]

You need to set the value to something other than required.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170622.1 | Last Updated 10 Nov 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100