2013-03-07 85 views
17

当我设置了Windows身份验证启用和匿名禁用在IIS中时,我得到以下错误。使Wcf服务集成Windows身份验证

主机 (“IntegratedWindowsAuthentication”)上配置的认证方案不允许 结合“basicHttpBinding的”(“匿名”)的那些配置。请确保将 SecurityMode设置为Transport或TransportCredentialOnly。 此外,这可以通过改变认证 方案为通过IIS管理工具本申请中,通过 的ServiceHost.Authentication.AuthenticationSchemes属性,则 应用配置文件中的 元件,通过在更新ClientCredentialType属性来解决 绑定,或通过调整 HttpTransportBindingElement上的AuthenticationScheme属性。

我的WCF服务的web.config如下:...

<?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> 

请咨询..

+0

您没有发布您的web.config ... – Tim 2013-03-07 06:59:30

+0

现在就准备好了。请指教。 – user214471 2013-03-07 07:04:05

+0

我在配置中看不到服务定义,只是客户端。如果这是您的服务的配置文件,并且您使用的是.NET 4.0以上版本,那么您很可能会得到一个默认终结点,这可能没有正确设置安全性。您还需要将您在配置文件中创建的绑定分配给您的服务。 – Tim 2013-03-07 07:07:05

回答

0
<services> 
     <service name="Test.Service1" behaviorConfiguration="TestName"> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" contract="Test.IService1" /> 
     </service> 
    </services> 

它解决了我的问题。

39

在.Net 4.0+,Simplified WCF configuration使用“匿名”配置时,如果未在<服务部分的服务基础上明确设置配置。如果您从<绑定>元素中删除名称=“BasicHttpEndpointBinding”,或者将该元素作为无name属性的新元素复制,则它将成为WCF服务将使用的默认匿名绑定。在需要服务和使用可能不都具有相同配置的WCF服务的情况下,这通常很有用 - 但至少您可以为没有特定配置集的服务设置默认配置。默认/匿名概念也适用于<行为>元素。

<bindings> 
    <basicHttpBinding> 
    <binding> <!--Notice, no name attribute set--> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Windows" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

另外,我想补充一点,如果你的WCF服务要求身份验证,这意味着你要么需要使用真正的用户帐户使用该服务,否则你将需要授予域\ CLIENTCOMPUTERNAME $帐户访问服务 - 所以,对许多人来说,适当的解决方案可能是将配置改为允许匿名访问(这在我的回答中没有讨论)。不过,我有时确实选择通过Windows(Kerberos)身份验证来保护我的WCF服务。

+0

谢谢你的回应和解释。我完全是一样的情况,但webHttpBinding。 – AFract 2016-03-31 14:00:00

0

像其他的答案,我需要更新我的web.config的结合,这样的:

<basicHttpBinding> 
    <binding name="basicHttpBindin1"> 
    <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Windows" /> 
    </security> 
    </binding> 
</basicHttpBinding> 

但我也需要升级我绑定的实例:

var binding = new BasicHttpBinding { MaxReceivedMessageSize = 1000000, ReaderQuotas = { MaxDepth = 200 } }; 

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; 
11

添加这个工作为了我。

 <bindings> 
     <webHttpBinding> 
      <binding> 
       <security mode="TransportCredentialOnly"> 
        <transport clientCredentialType="Windows" /> 
       </security> 
      </binding> 
     </webHttpBinding> 
    </bindings> 
+0

这一个没有在我的方案中工作,但scradams的答案 - 唯一的区别似乎是scradam使用basicHttpBinding和此引用webHttpBinding。这些关键词有什么区别? – Jeff 2015-11-06 02:27:32

+0

webHttpBinding用于REST JSON服务(例如在Web应用程序中),basicHttpBinding用于SOAP。请参阅http://stackoverflow.com/questions/2650785/basichttpbinding-vs-wshttpbinding-vs-webhttpbinding或有关不同绑定的WCF文档。 – AFract 2016-03-31 13:58:59

+0

这就是我所需要的 - 我一直在使用基于SSL类型认证的示例,虽然我改变了使用“TransportCredentialOnly”模式的方法,但仍然收到错误消息,因为我将clientCredentialType设置为“Basic”。谢谢! – 2017-02-20 22:01:37

1

我从.NET 4.0更新到.NET 4.5.2时出现此错误。我改变了clientCredentialType从

<security mode="TransportCredentialOnly"> 
    <transport clientCredentialType="None"/> 
</security> 

<security mode="TransportCredentialOnly"> 
    <transport clientCredentialType="InheritedFromHost"/> 
</security> 

但是,设置clientCredentialType = “窗口” 的效果一样好。

0

我已经添加了webHttpBinding并将我的端点指向安全设置需要的端点。如果没有我的端点使用的默认配置WCF绑定:

<services> 
    <service behaviorConfiguration="ServiceBehavior" name="Service"> 
    <endpoint address="" binding="webHttpBinding" contract="IService" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="ServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
<bindings> 
    <webHttpBinding> 
     <binding> 
     <!--Notice, no name attribute set--> 
     <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 
     </security> 
     </binding> 
    </webHttpBinding> 

</bindings> 
0

我不完全知道为什么,但是当我加入“厂”属性我.SVC文件(你需要明确地将其拖动到Visual Studio ),一切都只是工程 - 没有任何更改Web.config中的默认设置!

我加厂= “System.ServiceModel.Activation.WebServiceHostFactory”所以我.SVC文件,从这个去:

<%@ ServiceHost Language="C#" Debug="true" Service="ServiceNameSpace.ServiceName" CodeBehind="ServiceName.svc.cs" %>

这样:

<%@ ServiceHost Language="C#" Debug="true" Service="ServiceNameSpace.ServiceName" CodeBehind="ServiceName.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

的只有副作用似乎是,当您在浏览器中单击.SVC文件时,您会收到'未找到端点'错误,但服务在您处于无论如何,它正确地调用它。如前所述,我在.NET 4.6(Simplified WCF configuration)中使用了一个默认的Web.config,因此我可能还需要添加端点详细信息以便再次运行。