繁体   English   中英

对 WCF 休息服务的自定义基本身份验证不起作用

[英]Custom basic authentication to a WCF rest service doesn´t work

我已按照此其他线程上的步骤操作: 将基本 HTTP 身份验证添加到 WCF REST 服务

但是当我调用 Web 服务时,并没有要求我提供用户名和密码。 我在 UserNameAuthenticator 类中的所有方法中设置了断点,我发现这些方法中的任何一个都被调用。

所以我的问题是:这个类是在哪里创建的? 我应该在代码中的哪个位置调用这些方法? web.config 文件中是否有任何代码可以为我执行此操作?

提前致谢

为了设置 WCF Web 服务以在用户验证器中使用用户名和密码,您需要设置如下服务行为:

<behaviors>
  <endpointBehaviors>
    <behavior name="webHttpBehavior">
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
      <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentSessions="2147483647"
        maxConcurrentInstances="2147483647" />
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" 
                                customUserNamePasswordValidatorType="FullyQaulifiedNameSpace.UserValidatorClass, FullyQaulifiedNameSpace" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

用户名身份验证器 (UserValidatorClass) 将驻留在 Web 项目中,但可以从另一个引用的程序集调用代码。 UserValidator 代码如下所示:

using System.IdentityModel.Selectors;


namespace MyNameSpace.Web
{
public class UserValidator : UserNamePasswordValidator
{


    public UserValidator() : base()
    {

    }

    public override void Validate(string username, string password)
    {

    }
}
}

进入验证方法的最简单方法是将您的 Web 服务发布到 IIS,并附加到分配给您的 Web 服务的应用程序池的工作进程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM