如果你正在主持在IIS WCF服務,它會在ASP.NET工作進程中運行,這意味着你可以配置身份驗證和授權,你會與ASMX Web服務做:
<system.Web>
<authentication mode="Windows"/>
<authorization>
<allow roles=".\Administrators"/>
<deny users="*"/>
</authorization>
</system.Web>
然後,您將必須禁用在IIS中對您的端點的匿名訪問,而是啓用Windows集成身份驗證。
在IIS管理控制檯中,通過爲虛擬目錄啓用'屬性'對話框來實現此目的。然後,您將在'目錄安全'選項卡中找到安全設置。
當然,唯一可用的通信通道是HTTP。客戶必須在傳輸級提供在請求他們的Windows標識使用這些設置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WindowsSecurity">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/myservice"
binding="wsHttpBinding"
bindingConfiguration="WindowsSecurity"
contract="IMyService" />
</client>
</system.serviceModel>
請注意,如果你的服務端點使用的wsHttpBinding,那麼你也將有SSL添加到您的端點因爲這是WCF在使用傳輸級安全性時強制實施的要求。
如果你不是去爲basicHttpBinding的,你就能夠使用在WCF提供一個不太安全認證模式稱爲TransportCredentialOnly,這裏不再需要SSL。
有關更詳細的信息,here是WCF安全基礎結構的很好概述。
請注意,如果你想這樣做,你需要在你的web.config文件中啓用ASP.NET兼容模式。否則它不會工作(也不會拋出錯誤)。 – Rocklan 2012-09-20 23:49:19
注意:爲此,system.web/roleManager/@enabled必須爲false或省略,否則角色將是IIS .Net角色,而不是Windows組。 – Polyfun 2015-02-09 10:14:48