如果你正在主持在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