仅在 web.config 端点 BindingConfiguration 中有自定义用户名验证器就足够了吗?

编程入门 行业动态 更新时间:2024-10-21 22:52:22
本文介绍了仅在 web.config 端点 BindingConfiguration 中有自定义用户名验证器就足够了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个客户用户名/密码验证器.在 web.config 的 endpoints bindingConfiguration 属性中使用它是否足够,或者我是否需要在 Service 方法中显式调用它.我注意到当我不称它为服务操作时,它不会被调用.我做错了什么吗?

I have a Customer Username/Password validator. Is it sufficient enough to have it in the endpoints bindingConfiguration attribute in web.config or do I need to explicitly call it in the Service method. I noticed when I don't call it a Service operation, it doesn't get called. Am I doing something wrong?

这是我定义绑定部分的方式:

This is how I have my bindings section defined:

<bindings>
  <wsHttpBinding>
    <binding name="CustomAuthentication">
      <security mode="Message">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

这是我定义服务节点的方式:

This is how I have my service node defined:

<service behaviorConfiguration="CustomValidator" name="Test.TestService">

我的端点属性有它的 BindingConfiguration = "CustomAuthentication"

My endpoint attribute has its BindingConfiguration = "CustomAuthentication"

这就是我在 ServiceBehaviors 中定义行为的方式:

This is how I have a behavior in my ServiceBehaviors defined:

<behavior name="CustomValidator">
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom"
                                 customUserNamePasswordValidatorType="Test.CustomUserNameValidator, FuzionSync"/>

        <serviceCertificate findValue="MyWebSite" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>

        </serviceCredentials>

      <serviceMetadata httpGetEnabled="True"/>

    </behavior>

当我运行 wcf 测试客户端来调用服务调用时,它甚至没有调用 Validate 方法.我让它调用的唯一方法是将它放在一个要显式调用的操作中.

When I run the wcf test client to invoke the service call, it doesn't even call the Validate method. The only way I get it to call is if I put it in an operation to be called explicitly.

推荐答案

您需要在绑定配置和服务行为中指定这一点.这是它在我们的一个项目中的样子(重要的部分是 clientCredentialType="UserName"<serviceCredentials> 元素):

You need to specify this both in the binding configuration and in the service behavior. This is how it looks in one of our projects (the important parts are clientCredentialType="UserName" and the <serviceCredentials> element):

<bindings>
  <wsHttpBinding>
    <binding name="SSLWithCustomAuthentication">
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" proxyCredentialType="None" />
        <message clientCredentialType="UserName" 
                 negotiateServiceCredential="true"
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="customAuthenticationBehavior">
      <serviceCredentials>
        <userNameAuthentication 
          userNamePasswordValidationMode="Custom"
          customUserNamePasswordValidatorType="Namespace.YourValidator, AssemblyName"/>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

然后让您的服务使用 behaviorConfiguration="customAuthenticationBehavior".

and then have your service use behaviorConfiguration="customAuthenticationBehavior".

请注意,我认为 WCF 不允许您在没有 SSL 的情况下使用用户名身份验证.

Note that I don't think WCF lets you use UserName authentication without SSL.

这篇关于仅在 web.config 端点 BindingConfiguration 中有自定义用户名验证器就足够了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:27:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   自定义   用户名   足够了   web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!