【问题标题】:Form Authentication on NetTcpBinding in WCF serviceWCF 服务中 NetTcpBinding 的表单身份验证
【发布时间】:2012-09-30 12:26:50
【问题描述】:

我正在使用 WCF 服务,它有两个端点 WsHttpBinding 和 NetTcpBinding,并且该服务正在使用表单身份验证。服务托管在 IIS 7 上。

这与 WsHttpBinding 完美配合,但对 NetTcpBinding 无效。

以下语句失败:

FormsAuthentication.SetAuthCookie("COOKIENAME", false);

例外是:

Object reference not set to an instance of an object.

请分享您对此的想法。

【问题讨论】:

    标签: wcf exception wcf-binding nettcpbinding form-authentication


    【解决方案1】:

    表单身份验证需要协议本身不支持的 cookie/会话。 因此,WCF 服务的 NetTcpBinding 无法实现 Forms 认证。

    【讨论】:

      【解决方案2】:

      选项 1:

      As an Alternative:

      • 添加对 System.IdentityModelSystem.IdentityModel.Selectors 以及 WCF 程序集的引用。
      • 在绑定中将安全模式设置为消息
      • Message.ClientCredentialType 设置为MessageCredentialType.UserName
      • 创建一个派生自UserNamePasswordValidator 的类型并实现唯一的方法。如果用户名/密码对未通过验证,您应该抛出 SecurityTokenException。

      在您的服务主机实例的 Credentials 属性上,设置:

      • UserNameAuthentication.UserNamePasswordValidationModeUserNamePasswordValidationMode.Custom
      • UserNameAuthentication.CustomUserNamePasswordValidator 到您的 UserNamePasswordValidator 派生类的新实例。
      • 使用ServiceCertificate.SetCertificate()设置服务证书

      至于客户端凭据对话框,您可以自己制作一个,也可以在您的代理集上创建一个 proxy.ClientCredentials.UserName.UserNameproxy.ClientCredentials.UserName.Password,然后再打开代理/第一次使用它。或者您可以查看如何实现 System.ServiceModel.Dispatcher.IInteractiveChannelInitializer 来创建您自己的交互式初始化 UI。

      选项 2:

      Another Alternative这听起来更像你想做的事情..Passing FormsAuthentication cookie to a WCF service

      我为什么要为旧帖子提供答案 - 因为有人可能正在寻找答案。希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2011-11-03
        • 1970-01-01
        • 1970-01-01
        • 2010-11-24
        • 2011-06-24
        • 2011-02-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多