通过配置进行 WCF 模拟

发布于 2024-11-18 03:28:24 字数 2738 浏览 2 评论 0原文

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

我尝试了 WCF 服务模拟 中给出的建议,但并没有得到令人满意的结果。当我尝试导航到 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< 的服务< /a>.

谢谢!

的服务的 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();
    }
}

I have a simple WCF service that uses WSHttpBinding and Windows authentication. 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. When I try to navigate to the landing page for the WCF service, I see the error:

The contract operation 'GetAdvice'
requires Windows identity for
automatic impersonation. A Windows
identity that represents the caller is
not provided by binding
('WSHttpBinding','http://tempuri.org/')
for contract
('IMagicEightBallService','http://tempuri.org/'.

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). I'm just publishing the project to a local IIS folder and accessing the service at http://localhost/MagicEightBall/MagicEightBallService.svc.

Thanks!

UPDATE:

My service's 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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2024-11-25 03:28:24

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

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

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

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

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.
  • Impersonation in WCF also requires client to allow service to impersonate his identity so setting the configuration on the service is not enough.

Here you have some article about impersonation and all necessary / possible settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文