WCF web service error: the service cannot be activated because it does not support ASP.NET compatibility

I am trying to create a calm wcf web service. When I try to connect to the service through the client, I get the following error:

The service cannot be activated because it does not support ASP.NET compatibility. Compatibility with ASP.NET is included for this application. Disable ASP.NET compatibility mode in the web.config file, or add the AspNetCompatibilityRequirements attribute to the service type with the RequirementsMode parameter as Allowed or Required.

Others were having problems, but they fixed it with changes to their web.config. I performed their fix, but the problem still exists. here is my web.config:

<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="WebBehavior" > <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="MyServiceBehavior" name="myfirstwcf"> <endpoint address="ws" binding="basicHttpBinding" contract="Imyfirstwcf" /> <endpoint address="ws2" binding="wsHttpBinding" contract="Imyfirstwcf" /> <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" contract="Imyfirstwcf" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <serviceHostingEnvironment aspNetCompatibilityEnabled= "true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> 
+48
rest wcf
Aug 10 '12 at 14:52
source share
3 answers

In the main service, you can mark your service as:

 [AspNetCompatibilityRequirements( RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

From http://forums.silverlight.net/t/21944.aspx

+93
Aug 10 2018-12-12T00:
source share

he will work:

you change these lines in your code or add a line in web.config:

 <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> </system.serviceModel> 
+47
Apr 22 '14 at 11:01
source share

If someone has many services and services created using a custom ServiceHostFactory , then AspNetCompatibilityRequirementsAttribute can also be set in the CreateServiceHost method.

Example:

 public class HostFactory : ServiceHostFactory { protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { var host = new ServiceHost(serviceType, baseAddresses); //other relevent code to configure host end point etc if (host.Description.Behaviors.Contains(typeof(AspNetCompatibilityRequirementsAttribute))) { var compatibilityRequirementsAttribute = host.Description.Behaviors[typeof(AspNetCompatibilityRequirementsAttribute)] as AspNetCompatibilityRequirementsAttribute; compatibilityRequirementsAttribute.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed; } else { host.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute() { RequirementsMode =AspNetCompatibilityRequirementsMode.Allowed}); } return host; } } 
0
Sep 19 '16 at 12:14
source share



All Articles