简体   繁体   English

WCF 通过配置模拟

[英]WCF Impersonation through configuration

I have a simple WCF service that uses WSHttpBinding and Windows authentication.我有一个简单的 WCF 服务,它使用 WSHttpBinding 和 Windows 身份验证。 I'm trying to force the server to impersonate the client's identity upon every method call for this service.我试图强制服务器在每次调用此服务的方法时模拟客户端的身份。

I tried the advice given at WCF Service Impersonation , but am not exactly getting happy results.我尝试了WCF Service Impersonation给出的建议,但并没有得到满意的结果。 When I try to navigate to the landing page for the WCF service, I see the error:当我尝试导航到 WCF 服务的登录页面时,我看到了以下错误:

The contract operation 'GetAdvice' requires Windows identity for automatic impersonation.合约操作“GetAdvice”需要 Windows 身份才能自动模拟。 A Windows identity that represents the caller is not provided by binding ('WSHttpBinding',' http://tempuri.org/ ') for contract ('IMagicEightBallService',' http://tempuri.org/ '.代表调用者的 Windows 身份不是通过绑定 ('WSHttpBinding',' http://tempuri.org/ ') 为合同 ('IMagicEightBallService', ' Z80791B3AE7002CB88C2468 .

Any ideas on what this error's trying to tell me?关于这个错误试图告诉我什么的任何想法?

The entire solution can be browsed at ftp://petio.org/2011/07/01/MagicEightBall/ (or downloaded at http://petio.org/2011/07/01/MagicEightBall.zip ). The entire solution can be browsed at ftp://petio.org/2011/07/01/MagicEightBall/ (or downloaded at http://petio.org/2011/07/01/MagicEightBall.zip ). I'm just publishing the project to a local IIS folder and accessing the service at http://localhost/MagicEightBall/MagicEightBallService.svc .我只是将项目发布到本地 IIS 文件夹并访问http://localhost/MagicEightBall/MagicEightBallService.svc上的服务。

Thanks!谢谢!

UPDATE:更新:

My service's Web.config:我的服务的 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>

My service code:我的服务代码:

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

What about minimizing the whole problem to simplest reproducible code which you can simply show here?如何将整个问题最小化为最简单的可重现代码,您可以在这里简单地展示? Nobody is interested in downloading and reviewing whole your project.没有人有兴趣下载和审查您的整个项目。 Moreover for later reference the related code should be still here.此外,为了以后参考,相关代码应该仍然在这里。

I checked your just configurations of your project and your client code and I see two blocking issues:我检查了您的项目和客户端代码的刚刚配置,发现两个阻塞问题:

  • If you want to enforce impersonation from configuration you must use only bindings with windows authentication - your endpoint exposed over HTTPS is without authentication.如果要从配置中强制执行模拟,则必须仅使用具有 windows 身份验证的绑定 - 通过 HTTPS 公开的端点没有身份验证。
  • Impersonation in WCF also requires client to allow service to impersonate his identity so setting the configuration on the service is not enough. WCF 中的模拟还要求客户端允许服务模拟他的身份,因此在服务上设置配置是不够的。

Here you have some article about impersonation and all necessary / possible settings. 在这里,您有一些关于模拟和所有必要/可能的设置的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM