我有一个客户用户名/密码验证器。是否足以将其包含在web.config的端点bindingConfiguration属性中,还是需要在Service方法中显式调用它。我注意到当我不将其称为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方法。我调用它的唯一方法是将其放入要显式调用的操作中。

最佳答案

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

<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的情况下使用UserName身份验证。

关于c# - 仅在web.config端点BindingConfiguration中具有“自定义用户名”验证器就足够了吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5993024/

10-16 21:09