5

I posted a question yesterday about how to enable impersonation using WCF services here: WCF service not impersonating specified user in config?

I enabled aspnetCompatibilityMode but when I update my service proxy, it says "the service cannot be activated because it requires asp net compatibility". I'm not entirely sure what this means. If I change the setting to AspNetCompatibilityRequirementsMode.Allowed, it doesn't enable impersonation. I tried enabling the setting in both the web.config as well as via the class attribute.

Is there a way around this without setting my service's app pool to run as the user I need? Thanks.

Community
  • 1
  • 1
Ryan Peters
  • 7,608
  • 8
  • 41
  • 57
  • Have you enabled compatibility mode in your web.config as well? – el_tone Mar 03 '11 at 12:25
  • I have not done both. I have either enabled it in the service's web.config or on the class itself (I have not changed anything in my site's web.config). – Ryan Peters Mar 03 '11 at 12:28

1 Answers1

16

You must turn on AspNetCompatibility in web.config of site hosting your service:

<system.serviceModel>
  ...
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>

Because you are making your service implementation dependent on ASP.NET you should mark your service class with:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

Default value of AspNetCompatibilityRequirements.RequirementMode is NotAllowed so that is most probably reason for your exception.

JustADev
  • 258
  • 1
  • 8
  • 19
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670