Wednesday, February 25, 2015

the AspNetCompatibilityRequirements attribute and why you should care

This error...

The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.

 
 

...comes from this bit of Web.config:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />

 
 

You will see it when you try to reach a .svc endpoint for a WCF web service in a browser. The trick to fix this is to decorate the class in your .svc.cs file with this attribute:

[AspNetCompatibilityRequirements(RequirementsMode =
      AspNetCompatibilityRequirementsMode.Allowed)]

No comments:

Post a Comment