C# 通过配置进行WCF模拟

C# 通过配置进行WCF模拟,c#,wcf,windows-authentication,impersonation,C#,Wcf,Windows Authentication,Impersonation,我有一个简单的WCF服务,它使用WSHttpBinding和Windows身份验证。我试图强制服务器在每次调用此服务的方法时模拟客户端的身份 我尝试了在会议上给出的建议,但并没有得到满意的结果。当我尝试导航到WCF服务的登录页时,我看到错误: 合同操作“GetAdvice” 需要的Windows标识 自动模拟。窗户 表示调用方的标识是 不具约束力 ('WSHttpBinding','') 合同 (“IMagicEightBallService”,“” 你知道这个错误想告诉我什么吗 整个解决方案可

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

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

合同操作“GetAdvice” 需要的Windows标识 自动模拟。窗户 表示调用方的标识是 不具约束力 ('WSHttpBinding','') 合同 (“IMagicEightBallService”,“”

你知道这个错误想告诉我什么吗

整个解决方案可以在浏览(或在下载)。我只是将项目发布到本地IIS文件夹并访问位于的服务

谢谢

更新:

我的服务的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>

如何将整个问题最小化为最简单的可复制代码,您可以在此处简单显示?没有人对下载和查看整个项目感兴趣。此外,相关代码应仍在此处,以供以后参考

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

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

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

谢谢,我只需要模拟配置选项的正确组合。对于将来的其他人:如果您使用,那么您必须确保使用[OperationBehavior(…)]装饰您的所有服务方法。这给我造成了很多困惑,因为我错误地认为impersonateCallerForAllOperations会自动为我执行此操作。此外,这也导致我的东西损坏。我将它放在那里,不知道它到底是什么,但是(除了最后的评论)删除它修复了我的应用程序。你的链接看起来死掉了,但我找到了另一个好链接:
public class MagicEightBallService : IMagicEightBallService
{
    [OperationBehavior(Impersonation=ImpersonationOption.Required)]
    public string GetAdvice()
    {
        MagicEightBall ball = new MagicEightBall();
        return ball.GetAdvice();
    }
}