Click here to Skip to main content
11,645,087 members (68,515 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET WCF
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
Edited 10-Nov-11 3:47am
RaisKazi at 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 at 10-Nov-11 9:51am
it is specified aspNetCompatibilityEnabled and not aspnetcompatibilityenabled
RaisKazi at 10-Nov-11 10:01am
Yup, I realized it later :), "pre" tag seems to be converting it to small letters.
RaisKazi at 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 at 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
0 OriginalGriff 700
1 684
2 Sergey Alexandrovich Kryukov 473
3 CPallini 426
4 Afzaal Ahmad Zeeshan 418
0 OriginalGriff 1,065
1 Sergey Alexandrovich Kryukov 703
2 Afzaal Ahmad Zeeshan 702
3 DamithSL 681
4 CPallini 595

Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 10 Nov 2011
Copyright © CodeProject, 1999-2015
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