【问题标题】:WCF Impersonation through configuration通过配置进行 WCF 模拟
【发布时间】:2011-09-27 00:18:54
【问题描述】:

我有一个使用 WSHttpBinding 和 Windows 身份验证的简单 WCF 服务。我试图强制服务器在每次调用此服务的方法时模拟客户端的身份。

我尝试了WCF Service Impersonation 给出的建议,但并没有完全得到满意的结果。当我尝试导航到 WCF 服务的登录页面时,我看到了错误:

合约操作“GetAdvice” 需要 Windows 身份 自动模仿。一个窗口 代表调用者的身份是 非绑定提供 ('WSHttpBinding','http://tempuri.org/') 对于合同 ('IMagicEightBallService','http://tempuri.org/'.

关于这个错误试图告诉我什么的任何想法?

整个解决方案可以在ftp://petio.org/2011/07/01/MagicEightBall/ 浏览(或在http://petio.org/2011/07/01/MagicEightBall.zip 下载)。我只是将项目发布到本地 IIS 文件夹并访问http://localhost/MagicEightBall/MagicEightBallService.svc 的服务。

谢谢!

更新:

我的服务的 Web.config:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.serviceModel>

    <services>
      <service name="Petio.MagicEightBall.MagicEightBallService" behaviorConfiguration="MagicEightBallServiceBehavior">

        <endpoint name="WSHttpBinding_WindowsSecurity_IMagicEightBallService"
                  address="http://localhost/MagicEightBall/MagicEightBallService.svc"
                  binding="wsHttpBinding"
                  contract="Petio.MagicEightBall.IMagicEightBallService" />

        <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MagicEightBallServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceAuthorization impersonateCallerForAllOperations="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>
</configuration>

我的服务代码:

public class MagicEightBallService : IMagicEightBallService
{
    [OperationBehavior(Impersonation=ImpersonationOption.Required)]
    public string GetAdvice()
    {
        MagicEightBall ball = new MagicEightBall();
        return ball.GetAdvice();
    }
}

【问题讨论】:

    标签: c# wcf windows-authentication impersonation


    【解决方案1】:

    如何将整个问题最小化为最简单的可重现代码,您可以在这里简单地展示?没有人有兴趣下载和审查您的整个项目。此外,为了以后参考,相关代码应该仍然在这里。

    我检查了您刚刚配置的项目和客户端代码,发现两个阻塞问题:

    • 如果您想从配置中强制执行模拟,您必须仅使用带有 Windows 身份验证的绑定 - 您通过 HTTPS 公开的端点没有身份验证。
    • WCF 中的模拟还要求客户端允许服务模拟他的身份,因此在服务上设置配置是不够的。

    Here你有一些关于模拟和所有必要/可能的设置的文章。

    【讨论】:

    • 谢谢,我只需要模拟配置选项的正确组合。
    • 对于未来的其他人:如果您使用 ,那么您必须确保使用 [OperationBehavior(...)] 装饰所有服务的方法。这给我带来了很多困惑,因为我错误地认为 impersonateCallerForAllOperations 会自动为我执行此操作。
    • 另外, 导致我的东西坏了。我把它放在那里不知道它到底是什么,但是(除了最后一条评论)删除它修复了我的应用程序。
    • 你的链接看起来死了,不过我确实找到了另一个不错的链接:blogs.msdn.com/b/dsnotes/archive/2012/07/31/…
    猜你喜欢
    • 2010-11-20
    • 2011-03-18
    • 2019-02-14
    • 2016-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多