【发布时间】:2012-04-05 07:11:36
【问题描述】:
我正在四处寻找,试图解决我在使用 WCF 时遇到的问题。我对 WCF 很陌生,所以我不确定到底发生了什么。
我正在使用 Visual Studio 2010 并进行了新网站->WCF 服务。我创建了我的服务并在配置文件中,如果我设置aspNetCompatibilityEnabled="true",我会在通过我的网络浏览器访问服务时收到此错误。
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="true" 在[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] 修复它时会导致此错误。
在我看来,它们听起来就像在做同样的事情。此外,如果没有该属性,silverlight 将无法调用我的 WCF 方法。这是为什么呢?
如果需要,这是我的配置文件:
<?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有必要拥有它?
【问题讨论】:
标签: c# .net wcf silverlight web-services