Asp.net

WCF Web 服務錯誤:無法啟動該服務,因為它不支持 ASP.NET 兼容性

  • August 10, 2012

我正在嘗試創建一個寧靜的 wcf Web 服務。當我嘗試通過客戶端連接到服務時,出現以下錯誤:

> > 該服務無法啟動,因為它不支持 ASP.NET 兼容性。為此應用程序啟用了 ASP.NET 兼容性。在 web.config 中關閉 ASP.NET 兼容模式,或將 AspNetCompatibilityRequirements 屬性添加到服務類型,並將RequirementsMode 設置為“允許”或“必需”。 > > >

其他人遇到了問題,但他們通過更改 web.config 解決了問題。我已經實施了他們的修復,但問題仍然存在。這是我的 web.config:

<system.serviceModel>
   <behaviors>
     <endpointBehaviors>
       <behavior name="WebBehavior" >
          <webHttp />
       </behavior>
     </endpointBehaviors>
     <serviceBehaviors>
       <behavior name="MyServiceBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="true" />
       </behavior>
       <behavior name="">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="false" />
       </behavior>
     </serviceBehaviors>
   </behaviors>
   <services>
     <service behaviorConfiguration="MyServiceBehavior" name="myfirstwcf">
       <endpoint address="ws" binding="basicHttpBinding" 
                 contract="Imyfirstwcf" />
       <endpoint address="ws2" binding="wsHttpBinding" 
                 contract="Imyfirstwcf" />
       <endpoint address="" behaviorConfiguration="WebBehavior" 
                 binding="webHttpBinding" 
                 contract="Imyfirstwcf" />
       <endpoint address="mex" binding="mexHttpBinding" 
                 contract="IMetadataExchange" />
     </service>
   </services>
   <serviceHostingEnvironment aspNetCompatibilityEnabled= "true"
     multipleSiteBindingsEnabled="true"  />
 </system.serviceModel>

在您的主要服務上,您可以將您的服務標記為:

[AspNetCompatibilityRequirements(
       RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

來自<http://forums.silverlight.net/t/21944.aspx>

引用自:https://stackoverflow.com/questions/11904202