首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使Wcf服务成为IntegratedWindowsAuthentication

使Wcf服务成为IntegratedWindowsAuthentication
EN

Stack Overflow用户
提问于 2013-03-07 14:57:37
回答 8查看 47.1K关注 0票数 23

当我在IIS中将Windows身份验证启用和匿名设置为禁用时,我收到以下错误。

匿名主机上配置的身份验证方案('IntegratedWindowsAuthentication')不允许绑定'BasicHttpBinding‘(’

‘)上配置的身份验证方案。请确保将SecurityMode设置为传输或TransportCredentialOnly。此外,可以通过以下方式解决此问题:通过IIS管理工具更改此应用程序的身份验证方案、通过ServiceHost.Authentication.AuthenticationSchemes属性、在应用程序配置文件中的元素处、通过更新绑定的ClientCredentialType属性或通过调整HttpTransportBindingElement的AuthenticationScheme属性。

我的Wcf服务的web.config如下所示...

代码语言:javascript
复制
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint binding="basicHttpBinding" 
        bindingConfiguration="BasicHttpEndpointBinding"
        contract="Test.IService1" name="BasicHttpEndpoint" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceAuthenticationManager 
             authenticationSchemes="IntegratedWindowsAuthentication"/>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpBinding" scheme="http" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
         multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

请指教..

EN

回答 8

Stack Overflow用户

发布于 2013-11-01 02:48:52

在.Net 4.0+中,如果没有在一节中明确设置每个服务的配置,则将使用“匿名”配置。如果从元素中删除名称“BasicHttpEndpointBinding”,或者将该元素复制为没有名称属性的新元素,则它将成为您的WCF服务将使用的默认匿名绑定。在您需要提供和使用WCF服务的情况下,这通常很有用,这些服务可能并不都具有相同的配置-但至少您可以为没有特定配置集的服务设置默认配置。默认/匿名概念也适用于元素。

代码语言:javascript
复制
<bindings>
  <basicHttpBinding>
    <binding> <!--Notice, no name attribute set-->
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

此外,我可能会补充说,如果您的WCF服务需要身份验证,这意味着您将需要使用真实的用户帐户使用服务,或者您将需要授予DOMAIN\CLIENTCOMPUTERNAME$帐户访问服务的权限-因此,对于许多人来说,也许正确的解决方案可能是更改配置以允许匿名访问(这在我的答案中没有讨论)。不过,我有时确实会选择使用Windows (Kerberos)身份验证来保护我的WCF服务。

票数 50
EN

Stack Overflow用户

发布于 2014-11-01 05:39:52

添加这个对我来说很管用。

代码语言:javascript
复制
        <bindings>
        <webHttpBinding>
            <binding>
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows" />
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
票数 14
EN

Stack Overflow用户

发布于 2016-10-21 19:18:39

当我从.NET 4.0更新到.NET 4.5.2时,我得到了这个错误。我将clientCredentialType从

代码语言:javascript
复制
<security mode="TransportCredentialOnly">
    <transport clientCredentialType="None"/>
</security>

代码语言:javascript
复制
<security mode="TransportCredentialOnly">
    <transport clientCredentialType="InheritedFromHost"/>
</security>

但是,将clientCredentialType=设置为“Windows”也同样有效。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15264969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档