【问题标题】:WCF Custom Authentication not workingWCF 自定义身份验证不起作用
【发布时间】:2010-12-17 19:10:59
【问题描述】:

尝试为 wcf 服务实现简单的“用户名”/“密码”身份验证。但它只是不工作。没有错误/异常。 这是网络配置代码:

    <?xml version="1.0"?>
    <configuration>     
        <system.web>
            <compilation debug="true" targetFramework="4.0"/>
            <customErrors mode="Off"/>
        </system.web>
        <system.serviceModel>
      <services>
      <service name="XYZService"
               behaviorConfiguration="XYZBehavior">        
        <!-- use base address specified above, provide one endpoint -->
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="XYZBinding"
                  contract="IXYZService" />
        <!--<endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />-->
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="XYZBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
        <behaviors>
                <serviceBehaviors>
                    <behavior>
                        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                        <serviceMetadata httpGetEnabled="true"/>
                        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                        <serviceDebug includeExceptionDetailInFaults="true"/>
                        <serviceCredentials>
                            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="XYZBinding.LicensingServer.CCustomValidatorClass, XYZBinding.LicensingServer"/>
                        </serviceCredentials>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
        </system.serviceModel>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true"/>
        </system.webServer>
    </configuration>

验证码:

public class CCustomValidatorClass : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if(userName != "Test" || password != "1234567")
            {
                throw new FaultException("The provided credentials are invalid.");
            }
        }
    }

没有错误或异常。我无需任何凭据即可调用服务并执行。在本地调试时,验证方法永远不会被命中。

我不知道错过了什么。

【问题讨论】:

  • 我不是 WCF 专家,但在这些场景中的第一个问题始终是:“您确定正在使用此配置吗?”。通过更改配置中会破坏应用程序的内容来检查这一点,如果应用程序仍然有效,它正在使用另一个配置:-)
  • 刚刚更新了“customUserNamePasswordValidatorType”,wcf 测试客户端抛出了错误。改回原来的。 WCF 测试客户端运行顺畅。
  • 您没有向我们展示配置中重要且有趣的部分 - 部分。您甚至有实际使用这些绑定配置和那些安全设置的服务吗?从你到目前为止发布的内容来看,它看起来不像那样......
  • 没有定义 部分。也许这就是问题所在。我将添加/配置一个并更新它。
  • 更新了服务部分。现在我收到“此服务的安全设置需要‘基本’身份验证,但托管此服务的 IIS 应用程序未启用它。”错误。

标签: c# .net wcf authentication wcf-security


【解决方案1】:

服务是否托管在 IIS 中?如果是这样,这可能不受支持,因为 IIS 执行传输身份验证。 http://msdn.microsoft.com/en-us/library/aa702565.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-29
    • 2018-08-05
    • 1970-01-01
    • 2018-05-03
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多