【问题标题】:Using HMAC-SHA256 Authentication for WCF with HttpModule对带有 HttpModule 的 WCF 使用 HMAC-SHA256 身份验证
【发布时间】:2013-09-10 23:51:54
【问题描述】:

我正在尝试为我的 WCF 网络服务进行 HMAC-SHA256 身份验证。

在网上阅读了很多关于 HMAC-SHA 的内容后,我开始将它们应用到我的项目中。

现在我已经成功地在客户端加密了消息,但是如何在请求进入 WebMethods 之前对请求进行身份验证?

我想我应该添加一个 HttpModule 来利用 Init() 事件并在那里进行验证?

但是,一旦我将 HttpModule 添加到我的 WCF 项目并配置 web.config,我就会收到错误消息:

An error occurred while receiving the HTTP response to http://localhost:61884/MyService.svc.
This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down).
See server logs for more details.

在这种情况下使用 HttpModule 是否正确?

我的 web.config,以防万一

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpModules>
        <add name="HttpAuthenticationModule" type="WcfService.HttpAuthenticationModule" />
    </httpModules>
</system.web>

【问题讨论】:

  • 您的 web.config 缺少与 WCF 相关的所有内容。看看能不能连接到服务器上的正常网页。
  • WCF 很好。如果我从 web.config 中取出 httpModules 就可以了。我在这里排除了 ServiceModel 部分,因为 web.config 现在在另一台计算机上,我无法复制/粘贴,我在这里重新输入它们会很疯狂。我应该提到这一点。我的坏 =)
  • 你能添加HttpAuthenticationModule的代码清单吗?
  • @Aron HttpAuthenticationModule 中没有任何内容,我只是将其添加到项目中,没有任何实际实现。我在模块内的 Init() 处放了一个断点,以查看是否正在调用模块,但错误发生在它到达断点之前 =/
  • 啊...对...有实现吗?在应用程序生命周期的早期阶段,我发现调试器并不总是按预期工作。例如,我从来没有能够在Global.Init() 上休息。

标签: wcf hmac


【解决方案1】:

我认为 HttpModule 不适用于从 VisualStudio 启动的自托管 WCF 服务。在 IIS 中托管 WCF 服务后,HttpModule 正在 BeginRequest() 处命中断点,正如我现在所期望的那样。

希望这对面临同样问题的人有所帮助。

【讨论】:

    猜你喜欢
    • 2020-11-02
    • 2012-04-12
    • 1970-01-01
    • 2017-11-21
    • 2018-05-28
    • 2010-12-13
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多