2013-03-07 55 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,因此我可能還需要添加端點詳細信息以便再次運行。