WCF Service does not support ASP.NET compatibility

Published on Wednesday, September 29, 2010

When you create a WCF Service in ASP.NET, you might get an error page which includes the following content: Server Error in ‘/’ Application.

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'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: 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'.

The resolution is just add “[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]” to the service type:

For example:

namespace MyWebAPP
{
    <font color="#000099">**[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]**</font>
    public class MyWCFService : IMyWCFService
    {
        public void DoWork()
        {
        }
    }
}