为什么 AspNetCompatibilityRequirementsMode.Allowed 修复了这个错误? [英] Why does AspNetCompatibilityRequirementsMode.Allowed fix this error?

查看:14
本文介绍了为什么 AspNetCompatibilityRequirementsMode.Allowed 修复了这个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在四处寻找,试图解决我在 WCF 中遇到的问题.我对 WCF 很陌生,所以我不确定到底发生了什么.

I was searching around trying to solve a problem I am having with WCF. I am very new to WCF so I wasn't sure exactly what was going on.

我使用的是 Visual Studio 2010 并且做了新网站->WCF 服务.我创建了我的服务,并且在配置文件中,如果我设置了 aspNetCompatibilityEnabled="true",我会在通过 Web 浏览器访问该服务时收到此错误.

I am using Visual Studio 2010 and did New Web Site->WCF Service. I created my service and in the config file, if I set aspNetCompatibilityEnabled="true", I would get this error when going to 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'.

我不明白这是什么意思.当 [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] 修复它时,为什么 aspNetCompatibilityEnabled="true" 会导致此错误.

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

对我来说,它们听起来像是在做同样的事情.此外,如果没有该属性,silverlight 无法调用我的 WCF 方法.这是为什么?

To me, they sound like they do the same thing. Also, without that attribute silverlight was not able to call my WCF methods. Why is that?

如果需要,这是我的配置文件:

Here is my config 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>

所以我的问题是,为什么添加 Compatibility 属性可以解决这个问题?还有,为什么Silverlight 有必要拥有它?

So my question is, why does adding the Compatibility attribute fix that? Also, why was it necessary for silverlight to have it?

推荐答案

当您在配置文件中将 aspNetCompatibilityEnabled 设置为 true 时,您表示您的服务将参与在 ASP.NET 管道中;所以像 ASP.NET session 这样的项目是可用的.如果是这种情况,您需要适当地装饰您的服务,因为 ASP.NET 兼容模式默认设置为 false.

When you set aspNetCompatibilityEnabled to true in your config file, you are stating that your services will participate in the ASP.NET pipeline; so items like ASP.NET session are available. You need to decorate your services appropriately if this is the case, since ASP.NET Compatibility Mode is set to false by default.

因此,通过使用 AllowedRequirementsMode 装饰您的服务实现,您就表示了一个快乐的中间立场,基本上说您的服务不关心 aspNetCompatibility 模式是(真或假).如果您的 RequirementsModeRequired,那么您需要将配置 aspNetCompatibilityEnabled 设置为 true;如果您的 RequirementsMode 设置为 NotAllowed,则相反.

So by decorating your service implementation with a RequirementsMode of Allowed, you're stating a happy middle ground that basically says your service doesn't care what the aspNetCompatibility mode is (true or false). If your RequirementsMode is Required, then you need to have the config aspNetCompatibilityEnabled set to true; the opposite is true if your RequirementsMode is set to NotAllowed.

(如果您选择了允许的RequirementsMode 的中间立场,您可以通过检查静态ServiceHostingEnvironment.AspNetCompatibilityEnabled 属性.)

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

Silverlight 必须依赖于 ASP.NET 管道(我不是 Silverlight 开发人员),这就是为什么您需要在配置和服务中启用此兼容模式以便 Silverlight 调用它们应用.

Silverlight must have a dependency on the ASP.NET pipeline (I'm not a Silverlight developer), which is why you need to enable this compatibility mode in your config and on your services in order for them to be called by Silverlight apps.

此处查看 MSDN 文档.要知道的是,如果您不需要 ASP.NET 管道好东西,那么您不需要装饰您的服务或在您的配置中设置 aspNetCompatibilityEnabled 设置(默认情况下它们是关闭的).

Check out MSDN's documentation on this here. The thing to know is that if you don't need ASP.NET pipeline goodies, then you don't need to decorate your services or set the aspNetCompatibilityEnabled setting in your config (they're turned off by default).

这篇关于为什么 AspNetCompatibilityRequirementsMode.Allowed 修复了这个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆