【问题标题】:Is it sufficient just to have the Custom Username validator in the web.config endpoint BindingConfiguration?仅在 web.config 端点 BindingConfiguration 中有自定义用户名验证器就足够了吗?
【发布时间】:2011-05-13 22:23:57
【问题描述】:

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

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

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

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

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

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

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

<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 方法。我让它调用的唯一方法是,如果我把它放在一个要显式调用的操作中。

【问题讨论】:

  • 如果我是对的,在连接到 wcf 服务之前,您需要使用这些作为凭据。
  • @BreakHead,我对你的回复感到困惑?

标签: c# wcf


【解决方案1】:

您需要在绑定配置和服务行为中都指定这一点。这是它在我们的一个项目中的外观(重要部分是clientCredentialType="UserName"&lt;serviceCredentials&gt; 元素):

<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"

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

【讨论】:

  • 我更新了我的帖子。我在本地机器上有一个临时 SSL 证书。
  • 我觉得不错。顺便问一下,当客户端连接时,服务操作本身会被调用,还是什么都没有发生?
  • 当我通过 WCF 测试客户端运行它并单击 Invoke 时,它​​返回数据,但没有调用 Validate 方法。
  • @Xaisoft:看起来服务以某种方式没有“注意到”您的用户名配置,然后 - 不知道为什么。 (我似乎记得我们有一些与 IIS 相关的问题,通过将 &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/&gt; 添加到 Web.config 并将 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 添加到服务类,但我不确定它是否与此有关)。否则,恐怕我没有主意了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-15
  • 2021-03-09
  • 1970-01-01
相关资源
最近更新 更多