0

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

这与 WsHttpBinding 完美配合,但对 NetTcpBinding 失败。

它在以下声明中失败:

FormsAuthentication.SetAuthCookie("COOKIENAME", false);

例外是:

Object reference not set to an instance of an object.

请分享您对此的想法。

4

2 回答 2

0

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

于 2012-10-12T08:42:34.370 回答
0

选项1:

作为备选:

  • 添加对System.IdentityModel&System.IdentityModel.Selectors以及 WCF 程序集的引用。
  • 在绑定上将安全模式设置为 Message
  • 设置Message.ClientCredentialTypeMessageCredentialType.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:

另一种选择这听起来更像你想要做的.. 将FormsAuthentication cookie 传递给 WCF 服务

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

于 2015-11-17T18:15:08.987 回答