Why does AspNetCompatibilityRequirementsMode.Allowed fix this error?

I searched, trying to solve the problem that I encountered with WCF. I am very new to WCF, so I was not sure what was going on.

I am using Visual Studio 2010 and New Web Site-> WCF Service. I created my service also in the configuration file, if I set aspNetCompatibilityEnabled="true" , I would get this error when accessing the service through my web browser.

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

I do not understand what it means. Why aspNetCompatibilityEnabled="true" cause this error when [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] fixes it.

I think they are doing the same thing. Also, without this attribute, Silverlight could not call my WCF methods. Why is this?

Here is my configuration file, if necessary:

 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <customErrors mode="Off"/> </system.web> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="LargeBuffer" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" /> </basicHttpBinding> </bindings> <services> <service name="Services.Exporter"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeBuffer" contract="Services.IExporter" /> </service> </services> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration> 

So my question is: why add a compatibility attribute? Also, why is it necessary for Silverlight?

+26
c # web-services silverlight wcf
Mar 20 2018-12-12T00:
source share
1 answer

When you set aspNetCompatibilityEnabled to true in your configuration file, you declare that your services will participate in the ASP.NET pipeline; therefore, elements such as an ASP.NET session are available. You should appropriately decorate your services, if so, since ASP.NET compatibility mode is set to false by default.

So, decorating the implementation of your service with RequirementsMode Allowed , you declare a happy middle, which basically says that your service does not care that aspNetCompatibility mode (true or false). If your RequirementsMode is Required , you need to set the aspNetCompatibilityEnabled config aspNetCompatibilityEnabled to true; conversely, if your RequirementsMode set to NotAllowed .

(If you go with the happy Intermediate RequirementsMode of Allowed, you can check your service implementation if aspNetCompatibilityEnabled is enabled or not by checking the static ServiceHostingEnvironment.AspNetCompatibilityEnabled .)

Silverlight must be dependent on the ASP.NET pipeline (I'm not a Silverlight developer), so you need to enable this compatibility mode in your configuration and your services so that Silverlight applications call them.

Check out the MSDN documentation on this here . The fact is that if you do not need the attributes of the ASP.NET pipeline, you do not need to decorate your services or set the aspNetCompatibilityEnabled parameters in your config (they are disabled by default).

+36
Mar 20 '12 at 19:17
source share



All Articles