如何模拟用户到WCF服务?

时间:2013-08-02 15:08:20

标签: wcf authentication iis impersonation

我使用Windows身份验证和ASP.NET模拟通过IIS7对WCF服务的用户进行身份验证。

在本地调试时,我能够看到System.Security.Principal.WindowsIdentity.GetCurrent()。Name等于我的Windows凭据。当我将此服务部署到服务器时,除非启用匿名身份验证,否则WCF无法运行。

那么,我们如何让这个WCF服务在匿名身份验证已禁用 的服务器上运行?

更新1 :尝试这两项建议后出现错误消息:

  

主机上配置的身份验证方案   ('IntegratedWindowsAuthentication')不允许配置的那些   'WebHttpBinding'('Anonymous')绑定。请确保   SecurityMode设置为Transport或TransportCredentialOnly。   此外,这可以通过更改身份验证来解决   通过IIS管理工具,通过这个应用程序的方案   ServiceHost.Authentication.AuthenticationSchemes属性,在   应用程序配置文件在   element,通过更新绑定上的ClientCredentialType属性,   或者通过调整AuthenticationScheme属性   HttpTransportBindingElement。

更新2 :已按以下方式设置身份验证:

应用程序池:

  • Identity = NetworkService

网站:

  • 匿名身份验证=已停用
  • ASP.NET身份验证=已启用
  • Windows身份验证=已启用

WCF申请:

  • 匿名身份验证=已停用
  • ASP.NET身份验证=已启用
  • Windows身份验证=已启用

3 个答案:

答案 0 :(得分:3)

这是一个常见问题。您需要设置安全模式和相应的传输元素 - 如果使用basicHttpBinding - 在config

中放入以下文本
<basicHttpBinding>
   <binding>
     <security mode="TransportCredentialOnly">
     <transport clientCredentialType="Windows" />
     </security>
   </binding>
</basicHttpBinding>

阅读以下帖子 - http://blogs.msdn.com/b/drnick/archive/2007/03/23/preventing-anonymous-access.aspx http://blogs.msdn.com/b/wenlong/archive/2006/05/18/600603.aspx

答案 1 :(得分:1)

错误的原因之一是您需要在托管ASP.net的服务器上启用kerberos委派。这允许Windows身份验证令牌传播到WCF服务托管服务器。

您可以查看以下链接

Impersonation and Delegation in WCF

HTH

Rauts

答案 2 :(得分:0)

有同样的问题。对我来说,这是因为IIS上没有为应用程序启用Windows身份验证。

  1. 打开IIS
  2. 选择您的网络应用程序
  3. 单击“身份验证”图标(IIS)
  4. 启用Windows身份验证
相关问题