【问题标题】:How to get SOAP user name in WCF Service when using UserNamePasswordValidator?使用 UserNamePasswordValidator 时如何在 WCF 服务中获取 SOAP 用户名?
【发布时间】:2021-06-29 15:08:27
【问题描述】:

向我的 WCF 服务发出 SOAP 请求。如何访问请求的 Envelope.Header.Security.UserNameToken.Username 字段中使用的用户名? 我正在使用自定义 UserNamePasswordValidator 来检查凭据。

【问题讨论】:

    标签: security wcf


    【解决方案1】:

    在我的例子中,System.ServiceModel.ServiceSecurityContext.Current.PrimaryIdentity.Name 保存了UserNamePasswordValidator.Validate 方法中使用的用户名(来自请求的 SOAP 标头)。它可以在 WCF 服务类/方法中访问。

        public class Service1 : IService1
        {
            public Response ServiceMethod(Request request)
            {
                string userName = System.ServiceModel.ServiceSecurityContext.Current.PrimaryIdentity.Name;
                // ...
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2020-12-06
      • 1970-01-01
      相关资源
      最近更新 更多