IIS 7.5上的REST - IIS指定的身份验证方案异常

时间:2014-03-09 19:15:24

标签: c# wcf rest

首先,服务在IIS 7.5的Server 2008环境中正常运行。 Windows 7 / IIS 7.5环境中的相同服务显示以下错误:

[InvalidOperationException: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.]
   System.ServiceModel.Web.WebServiceHost.SetBindingCredentialBasedOnHostedEnvironment(ServiceEndpoint serviceEndpoint, AuthenticationSchemes supportedSchemes) +349683
   System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage, String standardEndpointKind) +806
   System.ServiceModel.Web.WebServiceHost.OnOpening() +244
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +274
   System.ServiceModel.Channels.CommunicationObject.Open() +36
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +184
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/IMonSapService' cannot be activated due to an exception during compilation.  The exception message is: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +687598
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +96

我的Global.asax.cs

中有以下行
RouteTable.Routes.Add(new ServiceRoute("IMonSapService", new WebServiceHostFactory(),
                    typeof(IMonSapService)));

这里是Service实现的第一行

[AspNetCompatibilityRequirements
    (RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class IMonSapService : IIMonSapService
{
...
}

我的web.config看起来像这样

 <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <httpRuntime />
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>

我比较了两个IIS实例,但我没有发现差异。

1 个答案:

答案 0 :(得分:0)

在applicationHost.config中找到它

<authentication>
    <anonymousAuthentication enabled="true" userName="IUSR"/>
    <basicAuthentication enabled="false"/>
    <clientCertificateMappingAuthentication/>
    <digestAuthentication/>
    <iisClientCertificateMappingAuthentication/>
    <windowsAuthentication enabled="true"/>
</authentication>

将windowsAuthentication更改为

    <windowsAuthentication enabled="false"/>

解决了这个问题。我认为在IIS管理器/身份验证中,所有内容都已禁用,但我必须在配置文件中更改此内容。

相关问题