为什么AspNetCompatibilityRequirementsMode.Allowed解决这个错误? [英] Why does AspNetCompatibilityRequirementsMode.Allowed fix this error?

查看:1337
本文介绍了为什么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,做了新的Web站点 - > WCF服务。我建立了我的服务,并在配置文件中,如果设置了 aspNetCompatibilityEnabled =真正的,通过我的网络浏览器去服务的时候我会得到这个错误。

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

我不明白这是什么意思。为什么 aspNetCompatibilityEnabled =真正的的原因这个错误时, <$c$c>[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]修复它。

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 的您的配置文件,就表示您的服务将参加ASP.NET管道;所以可像ASP.NET会话项目。您需要适当地修饰你的服务,如果是这样的话,因为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.

因此​​,通过装饰你的服务实现了 RequirementsMode 允许,你在陈述一个快乐的中间地面的基本上说,你的服务不关心什么<​​code> aspNetCompatibility 模式(true或false)。如果你的 RequirementsMode 必需,那么你需要有配置 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的快乐的中间地带的宠物,你可以在你的服务实现检查是否aspNetCompatibilityEnabled已启用或不通过检查静态<一href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehostingenvironment.aspnetcompatibilityenabled.aspx">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文档在此<一个href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.aspx">here.要知道的是,如果你不需要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天全站免登陆