可以使用2種類型的身份驗證:wcf中的windows和用戶名,使用消息安全模式和證書進行身份驗證。我的用戶名認證CFG /代碼如下:
服務器CFG:
WCF混合身份驗證用戶名和WIndows
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceCredentialsBehavior">
<serviceCredentials>
<serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" />
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Util.CustomUserNameValidator, Util" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="MessageAndUserName">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client/>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
客戶CFG:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="LocalCertValidation">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService" >
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:48097/WCFServer/Service.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService"
contract="ServiceReference1.IService"
name="WSHttpBinding_IService" behaviorConfiguration="LocalCertValidation">
<identity>
<dns value ="cool" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
什麼改變,服務器要知道,訪問Windows標識?
不,它不起作用。 也許我不正確設置Windows憑據,以及如何從服務器檢索它們? – croisharp
你真的需要2種不同的身份驗證方法嗎?您可以將客戶端的Windows憑據傳遞給服務,並允許該服務[模擬用戶](http://www.danrigsby.com/blog/index.php/2008/04/17/impersonate-a-clients-身份在-WCF /)。這可能比嘗試混合和匹配身份驗證類型更好。如果要驗證用戶名,可以將它們存儲在數據庫中,並將它們與'WindowsIdentity.GetCurrent()'返回的對象中模擬的客戶端用戶的詳細信息進行比較(最好存儲sid,因爲可以更改用戶名) – Franchesca
是的,我需要2身份驗證。方法+與NetSqlAzMan授權,但我知道所有如何做,這是我的問題與混合認證.. – croisharp