我正在四處搜尋,試圖解決我在使用WCF時遇到的問題。我對WCF很陌生,所以我不確定到底發生了什麼。爲什麼AspNetCompatibilityRequirementsMode.Allowed修復此錯誤?
我正在使用Visual Studio 2010並做了新網站 - > WCF服務。我創建了我的服務,並且在配置文件中,如果我設置了aspNetCompatibilityEnabled="true"
,則在通過我的Web瀏覽器訪問服務時會出現此錯誤。
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需要它?
問題,如果將它設置爲true,那麼這將是什麼合適的裝飾? – Justin 2012-03-20 19:32:18
這取決於您的服務是否需要ASP.NET管道提供的項目。如果你真的不在乎,那麼你將它設置爲'RequirementsMode.Allowed'。如果你依賴這些組件(比如Session),那麼你應該把它設置爲'RequirementsMode.Required'。 – 2012-03-20 19:37:31