WCF Web服务错误:无法激活该服务,因为它不支持ASP.NET兼容性

use*_*651 55 asp.net rest wcf

我正在尝试创建一个宁静的wcf Web服务.当我尝试通过客户端连接到服务时,我收到以下错误:

无法激活该服务,因为它不支持ASP.NET兼容性.为此应用程序启用了ASP.NET兼容性.在web.config中关闭ASP.NET兼容模式,或者将AspNetCompatibilityRequirements属性添加到服务类型,其RequirementsMode设置为"Allowed"或"Required".

其他人遇到了问题,但他们通过更改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>
Run Code Online (Sandbox Code Playgroud)

Waq*_*jua 105

在您的主要服务上,您可以将您的服务标记为:

[AspNetCompatibilityRequirements(
        RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Run Code Online (Sandbox Code Playgroud)

来自http://forums.silverlight.net/t/21944.aspx

  • 像魅力一样工作......也不要忘记在使用列表中添加System.ServiceModel.Activation命名空间 (3认同)
  • 谢谢你的工作.任何其他人正在使用vb.net ...语法是:<AspNetCompatibilityRequirements(RequirementsMode:= AspNetCompatibilityRequirementsMode.Required)>我真正需要的是用vb.net语法创建restful wcf的一个很好的例子,但我能找到的只是C#示例,我花时间尝试转换为vb.net.如果有人知道vb.net中的好示例代码,请告诉我,或者给我一个链接 (2认同)
  • 当我将操作系统从Win7切换到Win8时,我已经得到了这个.即使调试项目也行不通.IIS8上的某些内容使WCF服务上的此配置成为必需.谢谢史蒂夫!:) (2认同)

小智 53

它会工作:

您已在代码中更改此行或在web.config中添加行:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

  • 为什么这个被贬低它只是解决了我的问题! (2认同)
  • 这解决了我的问题,改变了`````aspNetCompatibilityEnabled ="false"```` (2认同)